---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-projects
  namespace: jnp2
  labels:
    app: jnp2
    tier: backend
    component: mysql-projects
spec:
  selector:
    matchLabels:
      app: jnp2
      tier: backend
      component: mysql-projects
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: jnp2
        tier: backend
        component: mysql-projects
    spec:
      containers:
        - name: mysql
          image: mysql:5.6
          imagePullPolicy: 'Always'
          env:
            - name: MYSQL_DATABASE
              value: 'projects'
            - name: MYSQL_USER
              value: 'projects'
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-projects
                  key: password
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-projects
                  key: root-password
          ports:
            - name: mysql
              containerPort: 3306
          livenessProbe:
            exec:
              command: ['sh', '-c', 'exec mysqladmin status -uroot -p"$MYSQL_ROOT_PASSWORD"']
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 1
            successThreshold: 1
            failureThreshold: 5
          readinessProbe:
            exec:
              command: ['sh', '-c', 'exec mysqladmin status -uroot -p"$MYSQL_ROOT_PASSWORD"']
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 1
            successThreshold: 1
            failureThreshold: 5
          volumeMounts:
            - name: data
              mountPath: /var/lib/mysql
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: mysql-projects-pvc