apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: db
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: mysql
  serviceName: mysql
  replicas: 1
  template:
    metadata:
      labels:
        app: wordpress
        tier: mysql
    spec:
      serviceAccountName: mysql
      securityContext:
        runAsUser: 0
        fsGroup: 999
      containers:
      - name: mysql
        image: mysql:5.7
        env:
          - name: MYSQL_ROOT_PASSWORD
            valueFrom:
              secretKeyRef:
                name: wordpress-mysql
                key: mysql-root-password
        ports:
        - name: mysql
          containerPort: 3306
        volumeMounts:
        - name: mysql-data
          mountPath: /var/lib/mysql
          subPath: mysql
        - name: conf
          mountPath: /etc/mysql/mysql.conf.d
        resources:
          requests:
            cpu: 500m
            memory: 1Gi
      volumes:
      - name: conf
        configMap:
          name: wordpress-mysql
  volumeClaimTemplates:
  - metadata:
      name: mysql-data
    spec:
      accessModes: ["ReadWriteOnce"]
      storageClassName: "fast" # StorageOS storageClass
      resources:
        requests:
          storage: 10Gi
