apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql
spec:
  serviceName: mysql8-service
  selector:
    matchLabels:
      app: mysql8
  template:
    metadata:
      labels:
        app: mysql8
    spec:
      containers:
      - image: mysql:8.0
        name: mysql
        imagePullPolicy: IfNotPresent
        resources:
          requests:
            memory: "{{ .Values.mysql.requestMemory }}"
            cpu: "{{ .Values.mysql.requestCpu }}"
          limits:
            cpu: "{{ .Values.mysql.limitCpu }}"
            memory: "{{ .Values.mysql.limitMemory }}"
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-root-pass
              key: MYSQL_ROOT_PASSWORD
        - name: MYSQL_DATABASE
          valueFrom:
            configMapKeyRef:
              name: userdb-config
              key: MYSQL_DATABASE
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef:
              name: db-user-pass
              key: MYSQL_USER
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-user-pass
              key: MYSQL_PASSWORD
        args: ["--default-authentication-plugin=mysql_native_password"]
        ports:
        - containerPort: 3306
          name: mysql8
        volumeMounts:
          - name: mysql-persistent-storage
            mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim-mysql-0
  volumeClaimTemplates:
  - metadata:
      name: mysql-pv-claim
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: "{{ .Values.mysql.storage }}"

