service-external-access.yaml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. {{- if $.Values.externalAccess.enabled }}
  2. {{- $shards := $.Values.shards | int }}
  3. {{- $replicas := $.Values.replicaCount | int }}
  4. {{- $totalNodes := mul $shards $replicas }}
  5. {{- range $shard, $e := until $shards }}
  6. {{- range $i, $_e := until $replicas }}
  7. {{- $targetPod := printf "%s-shard%d-%d" (include "common.names.fullname" $) $shard $i }}
  8. apiVersion: v1
  9. kind: Service
  10. metadata:
  11. name: {{ printf "%s-external" $targetPod | trunc 63 | trimSuffix "-" }}
  12. namespace: {{ $.Release.Namespace | quote }}
  13. labels: {{- include "common.labels.standard" $ | nindent 4 }}
  14. app.kubernetes.io/component: clickhouse
  15. pod: {{ $targetPod }}
  16. {{- if $.Values.commonLabels }}
  17. {{- include "common.tplvalues.render" ( dict "value" $.Values.commonLabels "context" $ ) | nindent 4 }}
  18. {{- end }}
  19. {{- if $.Values.externalAccess.service.labels }}
  20. {{- include "common.tplvalues.render" ( dict "value" $.Values.externalAccess.service.labels "context" $) | nindent 4 }}
  21. {{- end }}
  22. {{- if or $.Values.externalAccess.service.annotations $.Values.commonAnnotations $.Values.externalAccess.service.loadBalancerAnnotations }}
  23. annotations:
  24. {{- if and (not (empty $.Values.externalAccess.service.loadBalancerAnnotations)) (eq (len $.Values.externalAccess.service.loadBalancerAnnotations) $totalNodes) }}
  25. {{ include "common.tplvalues.render" ( dict "value" (index $.Values.externalAccess.service.loadBalancerAnnotations $i) "context" $) | nindent 4 }}
  26. {{- end }}
  27. {{- if $.Values.externalAccess.service.annotations }}
  28. {{- include "common.tplvalues.render" ( dict "value" $.Values.externalAccess.service.annotations "context" $) | nindent 4 }}
  29. {{- end }}
  30. {{- if $.Values.commonAnnotations }}
  31. {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
  32. {{- end }}
  33. {{- end }}
  34. spec:
  35. type: {{ $.Values.externalAccess.service.type }}
  36. {{- if eq $.Values.externalAccess.service.type "LoadBalancer" }}
  37. {{- if and (not (empty $.Values.externalAccess.service.loadBalancerIPs)) (eq (len $.Values.externalAccess.service.loadBalancerIPs) $totalNodes) }}
  38. loadBalancerIP: {{ index $.Values.externalAccess.service.loadBalancerIPs $i }}
  39. {{- end }}
  40. {{- if $.Values.externalAccess.service.loadBalancerSourceRanges }}
  41. loadBalancerSourceRanges: {{- toYaml $.Values.externalAccess.service.loadBalancerSourceRanges | nindent 4 }}
  42. {{- end }}
  43. {{- end }}
  44. ports:
  45. - name: http
  46. port: {{ $.Values.externalAccess.service.ports.http }}
  47. targetPort: http
  48. {{- if not (empty $.Values.externalAccess.service.nodePorts.http) }}
  49. nodePort: {{ index $.Values.externalAccess.service.nodePorts.http $i }}
  50. {{- else }}
  51. nodePort: null
  52. {{- end }}
  53. {{- if $.Values.tls.enabled }}
  54. - name: https
  55. port: {{ $.Values.externalAccess.service.ports.https }}
  56. targetPort: https
  57. {{- if not (empty $.Values.externalAccess.service.nodePorts.https) }}
  58. nodePort: {{ index $.Values.externalAccess.service.nodePorts.https $i }}
  59. {{- else }}
  60. nodePort: null
  61. {{- end }}
  62. {{- end }}
  63. {{- if $.Values.metrics.enabled }}
  64. - name: http-metrics
  65. port: {{ $.Values.externalAccess.service.ports.metrics }}
  66. targetPort: http-metrics
  67. {{- if not (empty $.Values.externalAccess.service.nodePorts.metrics) }}
  68. nodePort: {{ index $.Values.externalAccess.service.nodePorts.metrics $i }}
  69. {{- else }}
  70. nodePort: null
  71. {{- end }}
  72. {{- end }}
  73. - name: tcp
  74. port: {{ $.Values.externalAccess.service.ports.tcp }}
  75. targetPort: tcp
  76. {{- if not (empty $.Values.externalAccess.service.nodePorts.tcp) }}
  77. nodePort: {{ index $.Values.externalAccess.service.nodePorts.tcp $i }}
  78. {{- else }}
  79. nodePort: null
  80. {{- end }}
  81. {{- if $.Values.tls.enabled }}
  82. - name: tcp-secure
  83. port: {{ $.Values.externalAccess.service.ports.tcpSecure }}
  84. targetPort: tcp-secure
  85. {{- if not (empty $.Values.externalAccess.service.nodePorts.tcpSecure) }}
  86. nodePort: {{ index $.Values.externalAccess.service.nodePorts.tcpSecure $i }}
  87. {{- else }}
  88. nodePort: null
  89. {{- end }}
  90. {{- end }}
  91. {{- if $.Values.keeper.enabled }}
  92. - name: tcp-keeper
  93. port: {{ $.Values.externalAccess.service.ports.keeper }}
  94. targetPort: tcp-keeper
  95. {{- if not (empty $.Values.externalAccess.service.nodePorts.keeper) }}
  96. nodePort: {{ index $.Values.externalAccess.service.nodePorts.keeper $i }}
  97. {{- else }}
  98. nodePort: null
  99. {{- end }}
  100. - name: tcp-keeperinter
  101. port: {{ $.Values.externalAccess.service.ports.keeperInter }}
  102. targetPort: tcp-keeperinter
  103. {{- if not (empty $.Values.externalAccess.service.nodePorts.keeperInter) }}
  104. nodePort: {{ index $.Values.externalAccess.service.nodePorts.keeperInter $i }}
  105. {{- else }}
  106. nodePort: null
  107. {{- end }}
  108. {{- if $.Values.tls.enabled }}
  109. - name: tcp-keepertls
  110. port: {{ $.Values.externalAccess.service.ports.keeperSecure }}
  111. targetPort: tcp-keepertls
  112. {{- if not (empty $.Values.externalAccess.service.nodePorts.keeperSecure) }}
  113. nodePort: {{ index $.Values.externalAccess.service.nodePorts.keeperSecure $i }}
  114. {{- else }}
  115. nodePort: null
  116. {{- end }}
  117. {{- end }}
  118. {{- end }}
  119. - name: tcp-mysql
  120. port: {{ $.Values.externalAccess.service.ports.mysql }}
  121. targetPort: tcp-mysql
  122. {{- if not (empty $.Values.externalAccess.service.nodePorts.mysql) }}
  123. nodePort: {{ index $.Values.externalAccess.service.nodePorts.mysql $i }}
  124. {{- else }}
  125. nodePort: null
  126. {{- end }}
  127. - name: tcp-postgresql
  128. port: {{ $.Values.externalAccess.service.ports.postgresql }}
  129. targetPort: tcp-postgresql
  130. {{- if not (empty $.Values.externalAccess.service.nodePorts.postgresql) }}
  131. nodePort: {{ index $.Values.externalAccess.service.nodePorts.postgresql $i }}
  132. {{- else }}
  133. nodePort: null
  134. {{- end }}
  135. - name: tcp-intersrv
  136. port: {{ $.Values.externalAccess.service.ports.interserver }}
  137. targetPort: tcp-intersrv
  138. {{- if not (empty $.Values.externalAccess.service.nodePorts.interserver) }}
  139. nodePort: {{ index $.Values.externalAccess.service.nodePorts.interserver $i }}
  140. {{- else }}
  141. nodePort: null
  142. {{- end }}
  143. {{- if $.Values.externalAccess.service.extraPorts }}
  144. {{- include "common.tplvalues.render" (dict "value" $.Values.externalAccess.service.extraPorts "context" $) | nindent 4 }}
  145. {{- end }}
  146. selector: {{- include "common.labels.matchLabels" $ | nindent 4 }}
  147. app.kubernetes.io/component: clickhouse
  148. statefulset.kubernetes.io/pod-name: {{ $targetPod }}
  149. ---
  150. {{- end }}
  151. {{- end }}
  152. {{- end }}