---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demox-mysql-deployment
  namespace: demox
  labels:
    app: demox
spec:
  replicas: 1
  selector: 
    matchLabels:
      app: demox
      tier: database
  template:
    metadata:
      name: mysql
      labels:
        app: demox
        tier: database
    spec:
      volumes:
      - name: demox-varlibmysql
        persistentVolumeClaim:
          claimName: demox-mysql-pvc
      containers:
      - name: mysql
        image: mysql:8.0
        args: ["--default-authentication-plugin=mysql_native_password"]
        env:
        - name: MYSQL_USER
          valueFrom:
            configMapKeyRef:
              name: "demox-configmap"
              key: "MYSQL_USER"
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: "demox-secret"
              key: "MYSQL_PASSWORD"
        - name: MYSQL_DATABASE
          valueFrom:
            configMapKeyRef:
              name: "demox-configmap"
              key: "MYSQL_DATABASE"
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: "demox-secret"
              key: "MYSQL_PASSWORD"
        ports:
        - containerPort: 3306
        volumeMounts:
        - mountPath: "/var/lib/mysql"
          name: demox-varlibmysql