{{/* MySQL as a StatefulSet, not a Deployment: volumeClaimTemplates guarantees a single writer on the gp3 volume, the pod name is stable, and the PVC survives `helm uninstall` so an accidental teardown does not destroy data. */}} apiVersion: apps/v1 kind: StatefulSet metadata: name: {{ include "it-cost-dashboard.fullname" . }}-db labels: {{- include "it-cost-dashboard.componentLabels" (dict "ctx" . "component" "db") | nindent 4 }} spec: # Single-primary MySQL. NEVER raise this without real clustering — two pods # would fight over one RWO volume / diverge. replicas: 1 serviceName: {{ include "it-cost-dashboard.fullname" . }}-db-headless selector: matchLabels: {{- include "it-cost-dashboard.componentSelectorLabels" (dict "ctx" . "component" "db") | nindent 6 }} template: metadata: labels: {{- include "it-cost-dashboard.componentSelectorLabels" (dict "ctx" . "component" "db") | nindent 8 }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} containers: - name: mysql image: "{{ required "db.image.repository is required" .Values.db.image.repository }}:{{ required "db.image.tag is required" .Values.db.image.tag }}" imagePullPolicy: {{ .Values.db.image.pullPolicy }} ports: - name: mysql containerPort: {{ .Values.db.port }} protocol: TCP env: - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: {{ include "it-cost-dashboard.fullname" . }}-db-secret key: MYSQL_ROOT_PASSWORD - name: MYSQL_DATABASE valueFrom: secretKeyRef: name: {{ include "it-cost-dashboard.fullname" . }}-db-secret key: MYSQL_DATABASE # Generous initialDelay: the first boot runs both # /docker-entrypoint-initdb.d scripts (schema + 430 seed rows) before # opening TCP for real. readinessProbe: exec: command: - bash - -c - 'mysqladmin ping -u root -p"${MYSQL_ROOT_PASSWORD}" --silent' initialDelaySeconds: 30 periodSeconds: 10 timeoutSeconds: 5 failureThreshold: 12 livenessProbe: exec: command: - bash - -c - 'mysqladmin ping -u root -p"${MYSQL_ROOT_PASSWORD}" --silent' initialDelaySeconds: 120 periodSeconds: 20 timeoutSeconds: 5 failureThreshold: 6 volumeMounts: - name: mysql-data mountPath: /var/lib/mysql resources: {{- toYaml .Values.db.resources | nindent 12 }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.tolerations }} tolerations: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.affinity }} affinity: {{- toYaml . | nindent 8 }} {{- end }} volumeClaimTemplates: - metadata: name: mysql-data spec: accessModes: - ReadWriteOnce storageClassName: {{ .Values.db.storage.storageClassName }} resources: requests: storage: {{ .Values.db.storage.size }}