You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

deployment.yaml 8.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: {{ template "mysql.fullname" . }}
  5. namespace: {{ .Release.Namespace }}
  6. labels:
  7. app: {{ template "mysql.fullname" . }}
  8. chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
  9. release: "{{ .Release.Name }}"
  10. heritage: "{{ .Release.Service }}"
  11. {{- with .Values.deploymentAnnotations }}
  12. annotations:
  13. {{ toYaml . | indent 4 }}
  14. {{- end }}
  15. spec:
  16. strategy:
  17. {{ toYaml .Values.strategy | indent 4 }}
  18. selector:
  19. matchLabels:
  20. app: {{ template "mysql.fullname" . }}
  21. release: {{ .Release.Name }}
  22. template:
  23. metadata:
  24. labels:
  25. app: {{ template "mysql.fullname" . }}
  26. release: {{ .Release.Name }}
  27. {{- with .Values.podLabels }}
  28. {{ toYaml . | indent 8 }}
  29. {{- end }}
  30. {{- with .Values.podAnnotations }}
  31. annotations:
  32. {{ toYaml . | indent 8 }}
  33. {{- end }}
  34. spec:
  35. {{- if .Values.schedulerName }}
  36. schedulerName: "{{ .Values.schedulerName }}"
  37. {{- end }}
  38. {{- if .Values.imagePullSecrets }}
  39. imagePullSecrets:
  40. {{ toYaml .Values.imagePullSecrets | indent 8 }}
  41. {{- end }}
  42. {{- if .Values.priorityClassName }}
  43. priorityClassName: "{{ .Values.priorityClassName }}"
  44. {{- end }}
  45. {{- if .Values.securityContext.enabled }}
  46. securityContext:
  47. fsGroup: {{ .Values.securityContext.fsGroup }}
  48. runAsUser: {{ .Values.securityContext.runAsUser }}
  49. {{- end }}
  50. serviceAccountName: {{ template "mysql.serviceAccountName" . }}
  51. initContainers:
  52. - name: "remove-lost-found"
  53. image: "{{ .Values.busybox.image}}:{{ .Values.busybox.tag }}"
  54. imagePullPolicy: {{ .Values.imagePullPolicy | quote }}
  55. resources:
  56. {{ toYaml .Values.initContainer.resources | indent 10 }}
  57. command: ["rm", "-fr", "/var/lib/mysql/lost+found"]
  58. volumeMounts:
  59. - name: data
  60. mountPath: /var/lib/mysql
  61. {{- if .Values.persistence.subPath }}
  62. subPath: {{ .Values.persistence.subPath }}
  63. {{- end }}
  64. {{- if .Values.extraInitContainers }}
  65. {{ tpl .Values.extraInitContainers . | indent 6 }}
  66. {{- end }}
  67. {{- if .Values.nodeSelector }}
  68. nodeSelector:
  69. {{ toYaml .Values.nodeSelector | indent 8 }}
  70. {{- end }}
  71. {{- if .Values.affinity }}
  72. affinity:
  73. {{ toYaml .Values.affinity | indent 8 }}
  74. {{- end }}
  75. {{- if .Values.tolerations }}
  76. tolerations:
  77. {{ toYaml .Values.tolerations | indent 8 }}
  78. {{- end }}
  79. containers:
  80. - name: {{ template "mysql.fullname" . }}
  81. image: "{{ .Values.image }}:{{ .Values.imageTag }}"
  82. imagePullPolicy: {{ .Values.imagePullPolicy | quote }}
  83. {{- with .Values.args }}
  84. args:
  85. {{- range . }}
  86. - {{ . | quote }}
  87. {{- end }}
  88. {{- end }}
  89. resources:
  90. {{ toYaml .Values.resources | indent 10 }}
  91. env:
  92. {{- if .Values.mysqlAllowEmptyPassword }}
  93. - name: MYSQL_ALLOW_EMPTY_PASSWORD
  94. value: "true"
  95. {{- end }}
  96. {{- if not (and .Values.allowEmptyRootPassword (not .Values.mysqlRootPassword)) }}
  97. - name: MYSQL_ROOT_PASSWORD
  98. valueFrom:
  99. secretKeyRef:
  100. name: {{ template "mysql.secretName" . }}
  101. key: mysql-root-password
  102. {{- if .Values.mysqlAllowEmptyPassword }}
  103. optional: true
  104. {{- end }}
  105. {{- end }}
  106. {{- if not (and .Values.allowEmptyRootPassword (not .Values.mysqlPassword)) }}
  107. - name: MYSQL_PASSWORD
  108. valueFrom:
  109. secretKeyRef:
  110. name: {{ template "mysql.secretName" . }}
  111. key: mysql-password
  112. {{- if or .Values.mysqlAllowEmptyPassword (empty .Values.mysqlUser) }}
  113. optional: true
  114. {{- end }}
  115. {{- end }}
  116. - name: MYSQL_USER
  117. value: {{ default "" .Values.mysqlUser | quote }}
  118. - name: MYSQL_DATABASE
  119. value: {{ default "" .Values.mysqlDatabase | quote }}
  120. {{- if .Values.timezone }}
  121. - name: TZ
  122. value: {{ .Values.timezone }}
  123. {{- end }}
  124. {{- if .Values.extraEnvVars }}
  125. {{ tpl .Values.extraEnvVars . | indent 8 }}
  126. {{- end }}
  127. ports:
  128. - name: mysql
  129. containerPort: 3306
  130. {{- if .Values.mysqlx.port.enabled }}
  131. - name: mysqlx
  132. port: 33060
  133. {{- end }}
  134. livenessProbe:
  135. exec:
  136. command:
  137. {{- if .Values.mysqlAllowEmptyPassword }}
  138. - mysqladmin
  139. - ping
  140. {{- else }}
  141. - sh
  142. - -c
  143. - "mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}"
  144. {{- end }}
  145. initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
  146. periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
  147. timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
  148. successThreshold: {{ .Values.livenessProbe.successThreshold }}
  149. failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
  150. readinessProbe:
  151. exec:
  152. command:
  153. {{- if .Values.mysqlAllowEmptyPassword }}
  154. - mysqladmin
  155. - ping
  156. {{- else }}
  157. - sh
  158. - -c
  159. - "mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}"
  160. {{- end }}
  161. initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
  162. periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
  163. timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
  164. successThreshold: {{ .Values.readinessProbe.successThreshold }}
  165. failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
  166. volumeMounts:
  167. - name: data
  168. mountPath: /var/lib/mysql
  169. {{- if .Values.persistence.subPath }}
  170. subPath: {{ .Values.persistence.subPath }}
  171. {{- end }}
  172. {{- if .Values.configurationFiles }}
  173. {{- range $key, $val := .Values.configurationFiles }}
  174. - name: configurations
  175. mountPath: {{ $.Values.configurationFilesPath }}{{ $key }}
  176. subPath: {{ $key }}
  177. {{- end -}}
  178. {{- end }}
  179. {{- if .Values.initializationFiles }}
  180. - name: migrations
  181. mountPath: /docker-entrypoint-initdb.d
  182. {{- end }}
  183. {{- if .Values.ssl.enabled }}
  184. - name: certificates
  185. mountPath: /ssl
  186. {{- end }}
  187. {{- if .Values.extraVolumeMounts }}
  188. {{ tpl .Values.extraVolumeMounts . | indent 8 }}
  189. {{- end }}
  190. {{- if .Values.metrics.enabled }}
  191. - name: metrics
  192. image: "{{ .Values.metrics.image }}:{{ .Values.metrics.imageTag }}"
  193. imagePullPolicy: {{ .Values.metrics.imagePullPolicy | quote }}
  194. {{- if .Values.mysqlAllowEmptyPassword }}
  195. command:
  196. - 'sh'
  197. - '-c'
  198. - 'DATA_SOURCE_NAME="root@(localhost:3306)/" /bin/mysqld_exporter'
  199. {{- else }}
  200. env:
  201. - name: MYSQL_ROOT_PASSWORD
  202. valueFrom:
  203. secretKeyRef:
  204. name: {{ template "mysql.secretName" . }}
  205. key: mysql-root-password
  206. command:
  207. - 'sh'
  208. - '-c'
  209. - 'DATA_SOURCE_NAME="root:$MYSQL_ROOT_PASSWORD@(localhost:3306)/" /bin/mysqld_exporter'
  210. {{- end }}
  211. {{- range $f := .Values.metrics.flags }}
  212. - {{ $f | quote }}
  213. {{- end }}
  214. ports:
  215. - name: metrics
  216. containerPort: 9104
  217. livenessProbe:
  218. httpGet:
  219. path: /
  220. port: metrics
  221. initialDelaySeconds: {{ .Values.metrics.livenessProbe.initialDelaySeconds }}
  222. timeoutSeconds: {{ .Values.metrics.livenessProbe.timeoutSeconds }}
  223. readinessProbe:
  224. httpGet:
  225. path: /
  226. port: metrics
  227. initialDelaySeconds: {{ .Values.metrics.readinessProbe.initialDelaySeconds }}
  228. timeoutSeconds: {{ .Values.metrics.readinessProbe.timeoutSeconds }}
  229. resources:
  230. {{ toYaml .Values.metrics.resources | indent 10 }}
  231. {{- end }}
  232. volumes:
  233. {{- if .Values.configurationFiles }}
  234. - name: configurations
  235. configMap:
  236. name: {{ template "mysql.fullname" . }}-configuration
  237. {{- end }}
  238. {{- if .Values.initializationFiles }}
  239. - name: migrations
  240. configMap:
  241. name: {{ template "mysql.fullname" . }}-initialization
  242. {{- end }}
  243. {{- if .Values.ssl.enabled }}
  244. - name: certificates
  245. secret:
  246. secretName: {{ .Values.ssl.secret }}
  247. {{- end }}
  248. - name: data
  249. {{- if .Values.persistence.enabled }}
  250. persistentVolumeClaim:
  251. claimName: {{ .Values.persistence.existingClaim | default (include "mysql.fullname" .) }}
  252. {{- else }}
  253. emptyDir: {}
  254. {{- end -}}
  255. {{- if .Values.extraVolumes }}
  256. {{ tpl .Values.extraVolumes . | indent 6 }}
  257. {{- end }}