apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql
  namespace: wordpress-stack
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/creator: hossein-yousefi
    app.kubernetes.io/stack: wordpress
    app.kubernetes.io/env: production
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: mysql
      app.kubernetes.io/creator: hossein-yousefi
      app.kubernetes.io/stack: wordpress
      app.kubernetes.io/env: production
  serviceName: mysql
  replicas: 1    
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mysql
        app.kubernetes.io/creator: hossein-yousefi
        app.kubernetes.io/stack: wordpress
        app.kubernetes.io/env: production
    spec:
      containers:
      - image: mysql:5.7
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        - name: MYSQL_ROOT_HOST
          value: '%'
        - name: MYSQL_DATABASE
          value: wordpress
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-config-volume 
          mountPath: /etc/mysql/conf.d/default_auth.cnf 
          subPath: default_auth 
        - name: mysql-data
          mountPath: /var/lib/mysql
          
      volumes:
       - name: mysql-config-volume 
         configMap:
           name: mysql-config 
       - name: mysql-data
         persistentVolumeClaim:
          claimName: mysql-pv-claim
        
