apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql-statefuleset
  namespace: mysql
  labels:
    app-name: mysql
    version: ${MYSQL_VERSION}
    component: database-server
    hostNetwork: "no"
    internal-service: "yes"
    managed-by: chynten
    created-by: chynten
spec:
  replicas: 1
  selector:
    matchLabels:
      app-name: mysql
  serviceName: mysql-svc
  template:
    metadata:
      labels:
        app-name: mysql
    spec:
      containers:
        - name: mysql
          image: ${MYSQL_IMAGE}:${MYSQL_VERSION}
          args: ["--default-authentication-plugin=mysql_native_password"]
          resources:
            requests:
              cpu: "1"
              memory: "2048Mi"
          imagePullPolicy: IfNotPresent
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: mysql-root-password
#          livenessProbe:
#            exec:
#              command: ["mysqladmin", "ping", "-u", "root", "-p$ROOT_PASSWORD"]
#            initialDelaySeconds: 30
#            periodSeconds: 10
#            timeoutSeconds: 5
#          readinessProbe:
#            exec:
#              command: ["mysql", "-u", "root", "-p$ROOT_PASSWORD", "-e", "SELECT 1"]
#            initialDelaySeconds: 5
#            periodSeconds: 5
#            timeoutSeconds: 5
#          startupProbe:
#            exec:
#              command: ["mysql", "-u", "root", "-p$ROOT_PASSWORD", "-e", "SELECT 1"]
#            initialDelaySeconds: 30
#            periodSeconds: 5
#            timeoutSeconds: 10
          ports:
            - name: mysql
              containerPort: 3306
          volumeMounts:
            - name: data
              mountPath: /var/lib/mysql
            - name: mysql-initdb
              mountPath: /docker-entrypoint-initdb.d
      volumes:
        - name: config
          configMap:
            name: mysql
        - name: data
          persistentVolumeClaim:
            claimName: mysql-data-pvc
        - name: mysql-initdb
          configMap:
            name: mysql-initdb