apiVersion: apps/v1
kind: Deployment
metadata:
  name: db-deployment
spec:
  selector:
    matchLabels:
      component: db
  template:
    metadata:
      name: mysql-pod
      labels:
        component: db
    spec:
      volumes:
        - name: mysql-storage
          persistentVolumeClaim:
            claimName: db-pvc
      containers:
        - name: mysql
          image: mysql:5.7
          readinessProbe:
            tcpSocket:
              port: 3306
          livenessProbe:
            tcpSocket:
              port: 3306
          args:
            - --disable-partition-engine-check
          env:
            - name: MYSQL_RANDOM_ROOT_PASSWORD
              value: "yes"
            - name: MYSQL_DATABASE
              valueFrom:
                secretKeyRef:
                  name: db-secret
                  key: database
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  name: db-secret
                  key: username
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: db-secret
                  key: password
          volumeMounts:
            - name: mysql-storage
              mountPath: /var/lib/mysql
