statefulset.yaml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
  2. kind: StatefulSet
  3. metadata:
  4. name: {{ template "common.names.fullname" . }}
  5. namespace: {{ template "zookeeper.namespace" . }}
  6. labels: {{- include "common.labels.standard" . | nindent 4 }}
  7. app.kubernetes.io/component: zookeeper
  8. role: zookeeper
  9. {{- if .Values.commonLabels }}
  10. {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
  11. {{- end }}
  12. {{- if .Values.commonAnnotations }}
  13. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  14. {{- end }}
  15. spec:
  16. serviceName: {{ template "common.names.fullname" . }}-headless
  17. replicas: {{ .Values.replicaCount }}
  18. podManagementPolicy: {{ .Values.podManagementPolicy }}
  19. updateStrategy:
  20. type: {{ .Values.updateStrategy }}
  21. {{- if (eq "Recreate" .Values.updateStrategy) }}
  22. rollingUpdate: null
  23. {{- else if .Values.rollingUpdatePartition }}
  24. rollingUpdate:
  25. partition: {{ .Values.rollingUpdatePartition }}
  26. {{- end }}
  27. selector:
  28. matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
  29. app.kubernetes.io/component: zookeeper
  30. template:
  31. metadata:
  32. name: {{ template "common.names.fullname" . }}
  33. labels: {{- include "common.labels.standard" . | nindent 8 }}
  34. app.kubernetes.io/component: zookeeper
  35. {{- if .Values.podLabels }}
  36. {{- include "common.tplvalues.render" (dict "value" .Values.podLabels "context" $) | nindent 8 }}
  37. {{- end }}
  38. {{- if .Values.podAnnotations }}
  39. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
  40. {{- end }}
  41. spec:
  42. {{- if .Values.schedulerName }}
  43. schedulerName: {{ .Values.schedulerName }}
  44. {{- end }}
  45. {{- include "zookeeper.imagePullSecrets" . | nindent 6 }}
  46. serviceAccountName: {{ template "zookeeper.serviceAccountName" . }}
  47. {{- if .Values.securityContext.enabled }}
  48. securityContext:
  49. fsGroup: {{ .Values.securityContext.fsGroup }}
  50. {{- end }}
  51. {{- if .Values.hostAliases }}
  52. hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.hostAliases "context" $) | nindent 8 }}
  53. {{- end }}
  54. {{- if .Values.affinity }}
  55. affinity: {{- include "common.tplvalues.render" (dict "value" .Values.affinity "context" $) | nindent 8 }}
  56. {{- else }}
  57. affinity:
  58. podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAffinityPreset "component" "zookeeper" "context" $) | nindent 10 }}
  59. podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset "component" "zookeeper" "context" $) | nindent 10 }}
  60. nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values) | nindent 10 }}
  61. {{- end }}
  62. {{- if .Values.nodeSelector }}
  63. nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
  64. {{- end }}
  65. {{- if .Values.tolerations }}
  66. tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.tolerations "context" $) | nindent 8 }}
  67. {{- end }}
  68. {{- if .Values.priorityClassName }}
  69. priorityClassName: {{ .Values.priorityClassName }}
  70. {{- end }}
  71. {{- if or .Values.initContainers (and .Values.volumePermissions.enabled .Values.persistence.enabled) }}
  72. initContainers:
  73. {{- if .Values.initContainers }}
  74. {{ include "common.tplvalues.render" (dict "value" .Values.initContainers "context" $) | trim | nindent 8 }}
  75. {{- end }}
  76. {{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
  77. - name: volume-permissions
  78. image: {{ template "zookeeper.volumePermissions.image" . }}
  79. imagePullPolicy: {{ default "" .Values.volumePermissions.image.pullPolicy | quote }}
  80. command:
  81. - chown
  82. args:
  83. - -R
  84. - {{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }}
  85. - /bitnami/zookeeper
  86. {{- if .Values.dataLogDir }}
  87. - {{ .Values.dataLogDir }}
  88. {{- end }}
  89. securityContext:
  90. runAsUser: 0
  91. {{- if .Values.volumePermissions.resources }}
  92. resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }}
  93. {{- end }}
  94. volumeMounts:
  95. - name: data
  96. mountPath: /bitnami/zookeeper
  97. {{- if .Values.dataLogDir }}
  98. - name: data-log
  99. mountPath: {{ .Values.dataLogDir }}
  100. {{- end }}
  101. {{- end }}
  102. {{- end }}
  103. containers:
  104. - name: zookeeper
  105. image: {{ template "zookeeper.image" . }}
  106. imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
  107. {{- if .Values.securityContext.enabled }}
  108. securityContext:
  109. runAsUser: {{ .Values.securityContext.runAsUser }}
  110. {{- end }}
  111. command:
  112. - bash
  113. - -ec
  114. - |
  115. # Execute entrypoint as usual after obtaining ZOO_SERVER_ID
  116. # check ZOO_SERVER_ID in persistent volume via myid
  117. # if not present, set based on POD hostname
  118. if [[ -f "/bitnami/zookeeper/data/myid" ]]; then
  119. export ZOO_SERVER_ID="$(cat /bitnami/zookeeper/data/myid)"
  120. else
  121. HOSTNAME=`hostname -s`
  122. if [[ $HOSTNAME =~ (.*)-([0-9]+)$ ]]; then
  123. ORD=${BASH_REMATCH[2]}
  124. export ZOO_SERVER_ID=$((ORD + {{ .Values.minServerId }} ))
  125. else
  126. echo "Failed to get index from hostname $HOST"
  127. exit 1
  128. fi
  129. fi
  130. exec /entrypoint.sh /run.sh
  131. {{- if .Values.resources }}
  132. resources: {{- toYaml .Values.resources | nindent 12 }}
  133. {{- end }}
  134. env:
  135. - name: ZOO_DATA_LOG_DIR
  136. value: {{ .Values.dataLogDir | quote }}
  137. - name: ZOO_PORT_NUMBER
  138. value: {{ .Values.service.port | quote }}
  139. - name: ZOO_TICK_TIME
  140. value: {{ .Values.tickTime | quote }}
  141. - name: ZOO_INIT_LIMIT
  142. value: {{ .Values.initLimit | quote }}
  143. - name: ZOO_SYNC_LIMIT
  144. value: {{ .Values.syncLimit | quote }}
  145. - name: ZOO_MAX_CLIENT_CNXNS
  146. value: {{ .Values.maxClientCnxns | quote }}
  147. - name: ZOO_4LW_COMMANDS_WHITELIST
  148. value: {{ .Values.fourlwCommandsWhitelist | quote }}
  149. - name: ZOO_LISTEN_ALLIPS_ENABLED
  150. value: {{ ternary "yes" "no" .Values.listenOnAllIPs | quote }}
  151. - name: ZOO_AUTOPURGE_INTERVAL
  152. value: {{ .Values.autopurge.purgeInterval | quote }}
  153. - name: ZOO_AUTOPURGE_RETAIN_COUNT
  154. value: {{ .Values.autopurge.snapRetainCount | quote }}
  155. - name: ZOO_MAX_SESSION_TIMEOUT
  156. value: {{ .Values.maxSessionTimeout | quote }}
  157. - name: ZOO_SERVERS
  158. {{- $replicaCount := int .Values.replicaCount }}
  159. {{- $minServerId := int .Values.minServerId }}
  160. {{- $followerPort := int .Values.service.followerPort }}
  161. {{- $electionPort := int .Values.service.electionPort }}
  162. {{- $releaseNamespace := include "zookeeper.namespace" . }}
  163. {{- $zookeeperFullname := include "common.names.fullname" . }}
  164. {{- $zookeeperHeadlessServiceName := printf "%s-%s" $zookeeperFullname "headless" | trunc 63 }}
  165. {{- $clusterDomain := .Values.clusterDomain }}
  166. value: {{ range $i, $e := until $replicaCount }}{{ $zookeeperFullname }}-{{ $e }}.{{ $zookeeperHeadlessServiceName }}.{{ $releaseNamespace }}.svc.{{ $clusterDomain }}:{{ $followerPort }}:{{ $electionPort }}::{{ add $e $minServerId }} {{ end }}
  167. - name: ZOO_ENABLE_AUTH
  168. value: {{ ternary "yes" "no" .Values.auth.enabled | quote }}
  169. {{- if .Values.auth.enabled }}
  170. - name: ZOO_CLIENT_USER
  171. value: {{ .Values.auth.clientUser | quote }}
  172. - name: ZOO_CLIENT_PASSWORD
  173. valueFrom:
  174. secretKeyRef:
  175. name: {{ if .Values.auth.existingSecret }}{{ .Values.auth.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }}
  176. key: client-password
  177. - name: ZOO_SERVER_USERS
  178. value: {{ .Values.auth.serverUsers | quote }}
  179. - name: ZOO_SERVER_PASSWORDS
  180. valueFrom:
  181. secretKeyRef:
  182. name: {{ if .Values.auth.existingSecret }}{{ .Values.auth.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }}
  183. key: server-password
  184. {{- end }}
  185. - name: ZOO_HEAP_SIZE
  186. value: {{ .Values.heapSize | quote }}
  187. - name: ZOO_LOG_LEVEL
  188. value: {{ .Values.logLevel | quote }}
  189. - name: ALLOW_ANONYMOUS_LOGIN
  190. value: {{ ternary "yes" "no" .Values.allowAnonymousLogin | quote }}
  191. {{- if .Values.jvmFlags }}
  192. - name: JVMFLAGS
  193. value: {{ .Values.jvmFlags | quote }}
  194. {{- end }}
  195. {{- if .Values.metrics.enabled }}
  196. - name: ZOO_ENABLE_PROMETHEUS_METRICS
  197. value: "yes"
  198. - name: ZOO_PROMETHEUS_METRICS_PORT_NUMBER
  199. value: {{ .Values.metrics.containerPort | quote }}
  200. {{- end }}
  201. {{- if .Values.service.tls.client_enable }}
  202. - name: ZOO_TLS_CLIENT_ENABLE
  203. value: {{ .Values.service.tls.client_enable | quote }}
  204. - name: ZOO_TLS_CLIENT_KEYSTORE_FILE
  205. value: {{ .Values.service.tls.client_keystore_path | quote }}
  206. - name: ZOO_TLS_CLIENT_KEYSTORE_PASSWORD
  207. value: {{ .Values.service.tls.client_keystore_password | quote }}
  208. - name: ZOO_TLS_CLIENT_TRUSTSTORE_FILE
  209. value: {{ .Values.service.tls.client_truststore_path | quote }}
  210. - name: ZOO_TLS_CLIENT_TRUSTSTORE_PASSWORD
  211. value: {{ .Values.service.tls.client_truststore_password | quote }}
  212. {{ end }}
  213. {{- if .Values.service.tls.quorum_enable }}
  214. - name: ZOO_TLS_QUORUM_ENABLE
  215. value: {{ .Values.service.tls.quorum_enable | quote }}
  216. - name: ZOO_TLS_QUORUM_KEYSTORE_FILE
  217. value: {{ .Values.service.tls.quorum_keystore_path | quote }}
  218. - name: ZOO_TLS_QUORUM_KEYSTORE_PASSWORD
  219. value: {{ .Values.service.tls.quorum_keystore_password | quote }}
  220. - name: ZOO_TLS_QUORUM_TRUSTSTORE_FILE
  221. value: {{ .Values.service.tls.quorum_truststore_path | quote }}
  222. - name: ZOO_TLS_QUORUM_TRUSTSTORE_PASSWORD
  223. value: {{ .Values.service.tls.quorum_truststore_password | quote }}
  224. {{ end }}
  225. - name: POD_NAME
  226. valueFrom:
  227. fieldRef:
  228. apiVersion: v1
  229. fieldPath: metadata.name
  230. {{- if .Values.extraEnvVars }}
  231. {{- toYaml .Values.extraEnvVars | nindent 12 }}
  232. {{- end }}
  233. ports:
  234. {{ if not .Values.service.tls.disable_base_client_port }}
  235. - name: client
  236. containerPort: {{ .Values.service.port }}
  237. {{ end }}
  238. {{ if .Values.service.tls.client_enable }}
  239. - name: client-tls
  240. containerPort: {{ .Values.service.tls.client_port }}
  241. {{ end }}
  242. - name: follower
  243. containerPort: {{ .Values.service.followerPort }}
  244. - name: election
  245. containerPort: {{ .Values.service.electionPort }}
  246. {{- if .Values.metrics.enabled }}
  247. - name: metrics
  248. containerPort: {{ .Values.metrics.containerPort }}
  249. {{- end }}
  250. {{- if .Values.livenessProbe.enabled }}
  251. livenessProbe:
  252. exec:
  253. {{- if not .Values.service.tls.disable_base_client_port }}
  254. command: ['/bin/bash', '-c', 'echo "ruok" | timeout {{ .Values.livenessProbe.probeCommandTimeout }} nc -w {{ .Values.livenessProbe.probeCommandTimeout }} localhost {{ .Values.service.port }} | grep imok']
  255. {{- else }}
  256. {{- if not .Values.service.tls.client_enable }}
  257. command: ['/bin/bash', '-c', 'echo "ruok" | timeout {{ .Values.livenessProbe.probeCommandTimeout }} openssl s_client -quiet -crlf -connect localhost:{{ .Values.service.tls.client_port }} | grep imok']
  258. {{- else }}
  259. command: ['/bin/bash', '-c', 'echo "ruok" | timeout {{ .Values.livenessProbe.probeCommandTimeout }} openssl s_client -quiet -crlf -connect localhost:{{ .Values.service.tls.client_port }} -cert {{ .Values.service.tls.client_cert_pem_path }} -key {{ .Values.service.tls.client_key_pem_path }} | grep imok']
  260. {{- end }}
  261. {{- end }}
  262. initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
  263. periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
  264. timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
  265. successThreshold: {{ .Values.livenessProbe.successThreshold }}
  266. failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
  267. {{- end }}
  268. {{- if .Values.readinessProbe.enabled }}
  269. readinessProbe:
  270. exec:
  271. {{- if not .Values.service.tls.disable_base_client_port }}
  272. command: ['/bin/bash', '-c', 'echo "ruok" | timeout {{ .Values.readinessProbe.probeCommandTimeout }} nc -w {{ .Values.readinessProbe.probeCommandTimeout }} localhost {{ .Values.service.port }} | grep imok']
  273. {{- else }}
  274. {{- if not .Values.service.tls.client_enable }}
  275. command: ['/bin/bash', '-c', 'echo "ruok" | timeout {{ .Values.livenessProbe.probeCommandTimeout }} openssl s_client -quiet -crlf -connect localhost:{{ .Values.service.tls.client_port }} | grep imok']
  276. {{- else }}
  277. command: ['/bin/bash', '-c', 'echo "ruok" | timeout {{ .Values.livenessProbe.probeCommandTimeout }} openssl s_client -quiet -crlf -connect localhost:{{ .Values.service.tls.client_port }} -cert {{ .Values.service.tls.client_cert_pem_path }} -key {{ .Values.service.tls.client_key_pem_path }} | grep imok']
  278. {{- end }}
  279. {{- end }}
  280. initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
  281. periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
  282. timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
  283. successThreshold: {{ .Values.readinessProbe.successThreshold }}
  284. failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
  285. {{- end }}
  286. volumeMounts:
  287. - name: data
  288. mountPath: /bitnami/zookeeper
  289. {{- if .Values.dataLogDir }}
  290. - name: data-log
  291. mountPath: {{ .Values.dataLogDir }}
  292. {{- end }}
  293. {{- if .Values.config }}
  294. - name: config
  295. mountPath: /opt/bitnami/zookeeper/conf/zoo.cfg
  296. subPath: zoo.cfg
  297. {{- end }}
  298. {{- if .Values.extraVolumeMounts }}
  299. {{- toYaml .Values.extraVolumeMounts | nindent 12 }}
  300. {{- end }}
  301. volumes:
  302. {{- if .Values.config }}
  303. - name: config
  304. configMap:
  305. name: {{ template "common.names.fullname" . }}
  306. {{- end }}
  307. {{- if and .Values.persistence.enabled .Values.persistence.existingClaim }}
  308. - name: data
  309. persistentVolumeClaim:
  310. claimName: {{ printf "%s" (tpl .Values.persistence.existingClaim .) }}
  311. {{- else if not .Values.persistence.enabled }}
  312. - name: data
  313. emptyDir: {}
  314. {{- end }}
  315. {{- if and .Values.persistence.enabled .Values.persistence.dataLogDir.existingClaim }}
  316. - name: data-log
  317. persistentVolumeClaim:
  318. claimName: {{ printf "%s" (tpl .Values.persistence.dataLogDir.existingClaim .) }}
  319. {{- else if and ( not .Values.persistence.enabled ) .Values.dataLogDir }}
  320. - name: data-log
  321. emptyDir: {}
  322. {{- end }}
  323. {{- if .Values.extraVolumes }}
  324. {{- toYaml .Values.extraVolumes | nindent 8 }}
  325. {{- end }}
  326. {{- if and .Values.persistence.enabled (not (and .Values.persistence.existingClaim .Values.persistence.dataLogDir.existingClaim) )}}
  327. volumeClaimTemplates:
  328. {{- if not .Values.persistence.existingClaim }}
  329. - metadata:
  330. name: data
  331. annotations:
  332. {{- range $key, $value := .Values.persistence.annotations }}
  333. {{ $key }}: {{ $value }}
  334. {{- end }}
  335. spec:
  336. accessModes:
  337. {{- range .Values.persistence.accessModes }}
  338. - {{ . | quote }}
  339. {{- end }}
  340. resources:
  341. requests:
  342. storage: {{ .Values.persistence.size | quote }}
  343. {{- include "common.storage.class" (dict "persistence" .Values.persistence "global" .Values.global) | nindent 8 }}
  344. {{- end }}
  345. {{- if and (not .Values.persistence.dataLogDir.existingClaim) .Values.dataLogDir }}
  346. - metadata:
  347. name: data-log
  348. annotations:
  349. {{- range $key, $value := .Values.persistence.annotations }}
  350. {{ $key }}: {{ $value }}
  351. {{- end }}
  352. spec:
  353. accessModes:
  354. {{- range .Values.persistence.accessModes }}
  355. - {{ . | quote }}
  356. {{- end }}
  357. resources:
  358. requests:
  359. storage: {{ .Values.persistence.dataLogDir.size | quote }}
  360. {{- include "common.storage.class" (dict "persistence" .Values.persistence "global" .Values.global) | nindent 8 }}
  361. {{- end }}
  362. {{- end }}