statefulset.yaml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. {{- if eq .Values.architecture "replication" }}
  2. apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
  3. kind: StatefulSet
  4. metadata:
  5. name: {{ include "mysql.secondary.fullname" . }}
  6. namespace: {{ include "common.names.namespace" . | quote }}
  7. labels: {{- include "common.labels.standard" . | nindent 4 }}
  8. app.kubernetes.io/component: secondary
  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. replicas: {{ .Values.secondary.replicaCount }}
  17. podManagementPolicy: {{ .Values.secondary.podManagementPolicy | quote }}
  18. selector:
  19. matchLabels: {{ include "common.labels.matchLabels" . | nindent 6 }}
  20. app.kubernetes.io/component: secondary
  21. serviceName: {{ include "mysql.secondary.fullname" . }}
  22. {{- if .Values.secondary.updateStrategy }}
  23. updateStrategy: {{- toYaml .Values.secondary.updateStrategy | nindent 4 }}
  24. {{- end }}
  25. template:
  26. metadata:
  27. annotations:
  28. {{- if (include "mysql.secondary.createConfigmap" .) }}
  29. checksum/configuration: {{ include (print $.Template.BasePath "/secondary/configmap.yaml") . | sha256sum }}
  30. {{- end }}
  31. {{- if .Values.secondary.podAnnotations }}
  32. {{- include "common.tplvalues.render" (dict "value" .Values.secondary.podAnnotations "context" $) | nindent 8 }}
  33. {{- end }}
  34. labels: {{- include "common.labels.standard" . | nindent 8 }}
  35. app.kubernetes.io/component: secondary
  36. {{- if .Values.secondary.podLabels }}
  37. {{- include "common.tplvalues.render" ( dict "value" .Values.secondary.podLabels "context" $ ) | nindent 8 }}
  38. {{- end }}
  39. spec:
  40. serviceAccountName: {{ include "mysql.serviceAccountName" . }}
  41. {{- include "mysql.imagePullSecrets" . | nindent 6 }}
  42. {{- if .Values.secondary.hostAliases }}
  43. hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.hostAliases "context" $) | nindent 8 }}
  44. {{- end }}
  45. {{- if .Values.secondary.affinity }}
  46. affinity: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.affinity "context" $) | nindent 8 }}
  47. {{- else }}
  48. affinity:
  49. podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.secondary.podAffinityPreset "context" $) | nindent 10 }}
  50. podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.secondary.podAntiAffinityPreset "context" $) | nindent 10 }}
  51. nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.secondary.nodeAffinityPreset.type "key" .Values.secondary.nodeAffinityPreset.key "values" .Values.secondary.nodeAffinityPreset.values) | nindent 10 }}
  52. {{- end }}
  53. {{- if .Values.secondary.nodeSelector }}
  54. nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.nodeSelector "context" $) | nindent 8 }}
  55. {{- end }}
  56. {{- if .Values.secondary.tolerations }}
  57. tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.tolerations "context" $) | nindent 8 }}
  58. {{- end }}
  59. {{- if .Values.secondary.priorityClassName }}
  60. priorityClassName: {{ .Values.secondary.priorityClassName | quote }}
  61. {{- end }}
  62. {{- if .Values.secondary.runtimeClassName }}
  63. runtimeClassName: {{ .Values.secondary.runtimeClassName | quote }}
  64. {{- end }}
  65. {{- if .Values.secondary.schedulerName }}
  66. schedulerName: {{ .Values.secondary.schedulerName | quote }}
  67. {{- end }}
  68. {{- if .Values.secondary.topologySpreadConstraints }}
  69. topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.topologySpreadConstraints "context" .) | nindent 8 }}
  70. {{- end }}
  71. {{- if .Values.secondary.podSecurityContext.enabled }}
  72. securityContext: {{- omit .Values.secondary.podSecurityContext "enabled" | toYaml | nindent 8 }}
  73. {{- end }}
  74. {{- if .Values.secondary.terminationGracePeriodSeconds }}
  75. terminationGracePeriodSeconds: {{ .Values.secondary.terminationGracePeriodSeconds }}
  76. {{- end }}
  77. initContainers:
  78. {{- if and .Values.secondary.podSecurityContext.enabled .Values.volumePermissions.enabled .Values.secondary.persistence.enabled }}
  79. - name: volume-permissions
  80. image: {{ include "mysql.volumePermissions.image" . }}
  81. imagePullPolicy: {{ .Values.volumePermissions.image.pullPolicy | quote }}
  82. command:
  83. - /bin/bash
  84. - -ec
  85. - |
  86. mkdir -p "/bitnami/mysql"
  87. chown "{{ .Values.secondary.containerSecurityContext.runAsUser }}:{{ .Values.secondary.podSecurityContext.fsGroup }}" "/bitnami/mysql"
  88. find "/bitnami/mysql" -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | xargs -r chown -R "{{ .Values.secondary.containerSecurityContext.runAsUser }}:{{ .Values.secondary.podSecurityContext.fsGroup }}"
  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/mysql
  97. {{- if .Values.secondary.persistence.subPath }}
  98. subPath: {{ .Values.secondary.persistence.subPath }}
  99. {{- end }}
  100. {{- end }}
  101. {{- if .Values.secondary.initContainers }}
  102. {{- include "common.tplvalues.render" (dict "value" .Values.secondary.initContainers "context" $) | nindent 8 }}
  103. {{- end }}
  104. containers:
  105. - name: mysql
  106. image: {{ include "mysql.image" . }}
  107. imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
  108. {{- if .Values.secondary.containerSecurityContext.enabled }}
  109. securityContext: {{- omit .Values.secondary.containerSecurityContext "enabled" | toYaml | nindent 12 }}
  110. {{- end }}
  111. {{- if .Values.diagnosticMode.enabled }}
  112. command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
  113. {{- else if .Values.secondary.command }}
  114. command: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.command "context" $) | nindent 12 }}
  115. {{- end }}
  116. {{- if .Values.diagnosticMode.enabled }}
  117. args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
  118. {{- else if .Values.secondary.args }}
  119. args: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.args "context" $) | nindent 12 }}
  120. {{- end }}
  121. {{- if .Values.secondary.lifecycleHooks }}
  122. lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.lifecycleHooks "context" $) | nindent 12 }}
  123. {{- end }}
  124. env:
  125. - name: BITNAMI_DEBUG
  126. value: {{ ternary "true" "false" (or .Values.image.debug .Values.diagnosticMode.enabled) | quote }}
  127. - name: MYSQL_REPLICATION_MODE
  128. value: "slave"
  129. - name: MYSQL_MASTER_HOST
  130. value: {{ include "mysql.primary.fullname" . }}
  131. - name: MYSQL_MASTER_PORT_NUMBER
  132. value: {{ .Values.primary.service.ports.mysql | quote }}
  133. - name: MYSQL_MASTER_ROOT_USER
  134. value: "root"
  135. - name: MYSQL_REPLICATION_USER
  136. value: {{ .Values.auth.replicationUser | quote }}
  137. {{- if .Values.auth.usePasswordFiles }}
  138. - name: MYSQL_MASTER_ROOT_PASSWORD_FILE
  139. value: {{ default "/opt/bitnami/mysql/secrets/mysql-root-password" .Values.auth.customPasswordFiles.root }}
  140. - name: MYSQL_REPLICATION_PASSWORD_FILE
  141. value: {{ default "/opt/bitnami/mysql/secrets/mysql-replication-password" .Values.auth.customPasswordFiles.replicator }}
  142. {{- else }}
  143. - name: MYSQL_MASTER_ROOT_PASSWORD
  144. valueFrom:
  145. secretKeyRef:
  146. name: {{ template "mysql.secretName" . }}
  147. key: mysql-root-password
  148. - name: MYSQL_REPLICATION_PASSWORD
  149. valueFrom:
  150. secretKeyRef:
  151. name: {{ template "mysql.secretName" . }}
  152. key: mysql-replication-password
  153. {{- end }}
  154. {{- if .Values.secondary.extraFlags }}
  155. - name: MYSQL_EXTRA_FLAGS
  156. value: "{{ .Values.secondary.extraFlags }}"
  157. {{- end }}
  158. {{- if .Values.secondary.extraEnvVars }}
  159. {{- include "common.tplvalues.render" (dict "value" .Values.secondary.extraEnvVars "context" $) | nindent 12 }}
  160. {{- end }}
  161. envFrom:
  162. {{- if .Values.secondary.extraEnvVarsCM }}
  163. - configMapRef:
  164. name: {{ include "common.tplvalues.render" (dict "value" .Values.secondary.extraEnvVarsCM "context" $) }}
  165. {{- end }}
  166. {{- if .Values.secondary.extraEnvVarsSecret }}
  167. - secretRef:
  168. name: {{ include "common.tplvalues.render" (dict "value" .Values.secondary.extraEnvVarsSecret "context" $) }}
  169. {{- end }}
  170. ports:
  171. - name: mysql
  172. containerPort: 3306
  173. {{- if .Values.secondary.extraPorts }}
  174. {{- include "common.tplvalues.render" (dict "value" .Values.secondary.extraPorts "context" $) | nindent 12 }}
  175. {{- end }}
  176. {{- if not .Values.diagnosticMode.enabled }}
  177. {{- if .Values.secondary.customLivenessProbe }}
  178. livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.customLivenessProbe "context" $) | nindent 12 }}
  179. {{- else if .Values.secondary.livenessProbe.enabled }}
  180. livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.secondary.livenessProbe "enabled") "context" $) | nindent 12 }}
  181. exec:
  182. command:
  183. - /bin/bash
  184. - -ec
  185. - |
  186. password_aux="${MYSQL_MASTER_ROOT_PASSWORD:-}"
  187. if [[ -f "${MYSQL_MASTER_ROOT_PASSWORD_FILE:-}" ]]; then
  188. password_aux=$(cat "$MYSQL_MASTER_ROOT_PASSWORD_FILE")
  189. fi
  190. mysqladmin status -uroot -p"${password_aux}"
  191. {{- end }}
  192. {{- if .Values.secondary.customReadinessProbe }}
  193. readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.customReadinessProbe "context" $) | nindent 12 }}
  194. {{- else if .Values.secondary.readinessProbe.enabled }}
  195. readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.secondary.readinessProbe "enabled") "context" $) | nindent 12 }}
  196. exec:
  197. command:
  198. - /bin/bash
  199. - -ec
  200. - |
  201. password_aux="${MYSQL_MASTER_ROOT_PASSWORD:-}"
  202. if [[ -f "${MYSQL_MASTER_ROOT_PASSWORD_FILE:-}" ]]; then
  203. password_aux=$(cat "$MYSQL_MASTER_ROOT_PASSWORD_FILE")
  204. fi
  205. mysqladmin status -uroot -p"${password_aux}"
  206. {{- end }}
  207. {{- if .Values.secondary.customStartupProbe }}
  208. startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.customStartupProbe "context" $) | nindent 12 }}
  209. {{- else if .Values.secondary.startupProbe.enabled }}
  210. startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.secondary.startupProbe "enabled") "context" $) | nindent 12 }}
  211. exec:
  212. command:
  213. - /bin/bash
  214. - -ec
  215. - |
  216. password_aux="${MYSQL_MASTER_ROOT_PASSWORD:-}"
  217. if [[ -f "${MYSQL_MASTER_ROOT_PASSWORD_FILE:-}" ]]; then
  218. password_aux=$(cat "$MYSQL_MASTER_ROOT_PASSWORD_FILE")
  219. fi
  220. mysqladmin status -uroot -p"${password_aux}"
  221. {{- end }}
  222. {{- end }}
  223. {{- if .Values.secondary.resources }}
  224. resources: {{ toYaml .Values.secondary.resources | nindent 12 }}
  225. {{- end }}
  226. volumeMounts:
  227. - name: data
  228. mountPath: /bitnami/mysql
  229. {{- if .Values.secondary.persistence.subPath }}
  230. subPath: {{ .Values.secondary.persistence.subPath }}
  231. {{- end }}
  232. {{- if or .Values.initdbScriptsConfigMap .Values.initdbScripts }}
  233. - name: custom-init-scripts
  234. mountPath: /docker-entrypoint-initdb.d
  235. {{- end }}
  236. {{- if or .Values.secondary.configuration .Values.secondary.existingConfigmap }}
  237. - name: config
  238. mountPath: /opt/bitnami/mysql/conf/my.cnf
  239. subPath: my.cnf
  240. {{- end }}
  241. {{- if and .Values.auth.usePasswordFiles (not .Values.auth.customPasswordFiles) }}
  242. - name: mysql-credentials
  243. mountPath: /opt/bitnami/mysql/secrets/
  244. {{- end }}
  245. {{- if .Values.secondary.extraVolumeMounts }}
  246. {{- include "common.tplvalues.render" (dict "value" .Values.secondary.extraVolumeMounts "context" $) | nindent 12 }}
  247. {{- end }}
  248. {{- if .Values.metrics.enabled }}
  249. - name: metrics
  250. image: {{ include "mysql.metrics.image" . }}
  251. imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
  252. {{- if .Values.metrics.containerSecurityContext.enabled }}
  253. securityContext: {{- omit .Values.metrics.containerSecurityContext "enabled" | toYaml | nindent 12 }}
  254. {{- end }}
  255. env:
  256. {{- if .Values.auth.usePasswordFiles }}
  257. - name: MYSQL_ROOT_PASSWORD_FILE
  258. value: {{ default "/opt/bitnami/mysqld-exporter/secrets/mysql-root-password" .Values.auth.customPasswordFiles.root }}
  259. {{- else }}
  260. - name: MYSQL_ROOT_PASSWORD
  261. valueFrom:
  262. secretKeyRef:
  263. name: {{ template "mysql.secretName" . }}
  264. key: mysql-root-password
  265. {{- end }}
  266. {{- if .Values.diagnosticMode.enabled }}
  267. command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
  268. args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
  269. {{- else }}
  270. command:
  271. - /bin/bash
  272. - -ec
  273. - |
  274. password_aux="${MYSQL_ROOT_PASSWORD:-}"
  275. if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
  276. password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
  277. fi
  278. DATA_SOURCE_NAME="root:${password_aux}@(localhost:3306)/" /bin/mysqld_exporter {{- range .Values.metrics.extraArgs.secondary }} {{ . }} {{- end }}
  279. {{- end }}
  280. ports:
  281. - name: metrics
  282. containerPort: 9104
  283. {{- if not .Values.diagnosticMode.enabled }}
  284. {{- if .Values.metrics.livenessProbe.enabled }}
  285. livenessProbe: {{- omit .Values.metrics.livenessProbe "enabled" | toYaml | nindent 12 }}
  286. httpGet:
  287. path: /metrics
  288. port: metrics
  289. {{- end }}
  290. {{- if .Values.metrics.readinessProbe.enabled }}
  291. readinessProbe: {{- omit .Values.metrics.readinessProbe "enabled" | toYaml | nindent 12 }}
  292. httpGet:
  293. path: /metrics
  294. port: metrics
  295. {{- end }}
  296. {{- end }}
  297. {{- if .Values.metrics.resources }}
  298. resources: {{- toYaml .Values.metrics.resources | nindent 12 }}
  299. {{- end }}
  300. {{- if and .Values.auth.usePasswordFiles (not .Values.auth.customPasswordFiles) }}
  301. volumeMounts:
  302. - name: mysql-credentials
  303. mountPath: /opt/bitnami/mysqld-exporter/secrets/
  304. {{- end }}
  305. {{- end }}
  306. {{- if .Values.secondary.sidecars }}
  307. {{- include "common.tplvalues.render" (dict "value" .Values.secondary.sidecars "context" $) | nindent 8 }}
  308. {{- end }}
  309. volumes:
  310. {{- if or .Values.initdbScriptsConfigMap .Values.initdbScripts }}
  311. - name: custom-init-scripts
  312. configMap:
  313. name: {{ include "mysql.initdbScriptsCM" . }}
  314. {{- end }}
  315. {{- if or .Values.secondary.configuration .Values.secondary.existingConfigmap }}
  316. - name: config
  317. configMap:
  318. name: {{ include "mysql.secondary.configmapName" . }}
  319. {{- end }}
  320. {{- if and .Values.auth.usePasswordFiles (not .Values.auth.customPasswordFiles) }}
  321. - name: mysql-credentials
  322. secret:
  323. secretName: {{ template "mysql.secretName" . }}
  324. items:
  325. - key: mysql-root-password
  326. path: mysql-root-password
  327. - key: mysql-replication-password
  328. path: mysql-replication-password
  329. {{- end }}
  330. {{- if .Values.secondary.extraVolumes }}
  331. {{- include "common.tplvalues.render" (dict "value" .Values.secondary.extraVolumes "context" $) | nindent 8 }}
  332. {{- end }}
  333. {{- if and .Values.secondary.persistence.enabled .Values.secondary.persistence.existingClaim }}
  334. - name: data
  335. persistentVolumeClaim:
  336. claimName: {{ tpl .Values.secondary.persistence.existingClaim . }}
  337. {{- else if not .Values.secondary.persistence.enabled }}
  338. - name: data
  339. emptyDir: {}
  340. {{- else }}
  341. volumeClaimTemplates:
  342. - metadata:
  343. name: data
  344. labels: {{ include "common.labels.matchLabels" . | nindent 10 }}
  345. app.kubernetes.io/component: secondary
  346. {{- if .Values.commonLabels }}
  347. {{- include "common.tplvalues.render" (dict "value" .Values.commonLabels "context" $) | nindent 10 }}
  348. {{- end }}
  349. annotations:
  350. {{- if .Values.secondary.persistence.annotations }}
  351. {{- include "common.tplvalues.render" (dict "value" .Values.secondary.persistence.annotations "context" $) | nindent 10 }}
  352. {{- end }}
  353. {{- if .Values.commonAnnotations }}
  354. {{- include "common.tplvalues.render" (dict "value" .Values.commonAnnotations "context" $) | nindent 10 }}
  355. {{- end }}
  356. spec:
  357. accessModes:
  358. {{- range .Values.secondary.persistence.accessModes }}
  359. - {{ . | quote }}
  360. {{- end }}
  361. resources:
  362. requests:
  363. storage: {{ .Values.secondary.persistence.size | quote }}
  364. {{- include "common.storage.class" (dict "persistence" .Values.secondary.persistence "global" .Values.global) | nindent 8 }}
  365. {{- if .Values.secondary.persistence.selector }}
  366. selector: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.persistence.selector "context" $) | nindent 10 }}
  367. {{- end -}}
  368. {{- end }}
  369. {{- end }}