apiVersion: apps/v1
kind: Deployment
metadata:
  name: mariadb
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: mariadb
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: mariadb
      annotations:
        k8up.io/backupcommand: /bin/bash -c 'mysqldump -uroot -p"${MARIADB_ROOT_PASSWORD}" --all-databases'
    spec:
      containers:
      - image: mariadb:10.4
        name: mariadb
        readinessProbe:
          timeoutSeconds: 1
          initialDelaySeconds: 5
          exec:
            command:
            - "/bin/sh"
            - "-i"
            - "-c"
            - mysql -h 127.0.0.1 -uroot -p"${MARIADB_ROOT_PASSWORD}" -D mysql -e 'SELECT 1'
        livenessProbe:
          timeoutSeconds: 1
          initialDelaySeconds: 30
          tcpSocket:
            port: 3306
        env:
        - name: MARIADB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mariadb-pass
              key: password
        ports:
        - containerPort: 3306
          name: mariadb
        volumeMounts:
        - name: mariadb-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mariadb-persistent-storage
        persistentVolumeClaim:
          claimName: mariadb-pvc
