apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: backup-cronjob
spec:
  # should run every 12 hours of every day
  schedule: "0 */12 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          volumes:
            - name: backup-cronjob-configmap-volume
              configMap:
                name: backup-cronjob-configmap
                items:
                  - key: "backup_db.sh"
                    path: "backup.sh"

            - name: bp-backup-volume
              gcePersistentDisk:
                pdName: bp-backup-production-disk
          containers:
            - name: backup
              image: ubuntu:20.10
              args:
                - /bin/sh
                - -c
                - /bin/bash /script/backup.sh
              envFrom:
                - secretRef:
                    name: postgresql-secrets
              volumeMounts:
                - name: backup-cronjob-configmap-volume
                  mountPath: "/script/"
                - name: bp-backup-volume
                  mountPath: "/backups/"
          restartPolicy: OnFailure

