apiVersion: batch/v1
kind: Job
metadata:
  name: etcd-snapshot-once
  namespace: default
spec:
  backoffLimit: 3
  ttlSecondsAfterFinished: 60
  template:
    spec:
      containers:
        - name: backup
          # Same image as in /etc/kubernetes/manifests/etcd.yaml
          # Updated: 3.5.1-0 -> 3.5.30-0 (patch bump within 3.5.x, low risk)
          image: k8s.gcr.io/etcd:3.5.30-0
          env:
            - name: ETCDCTL_API
              value: "3"
          command: ["/bin/sh"]
          args: ["-c", "etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/etcd/ca.pem --cert=/etc/etcd/etcd.pem --key=/etc/etcd/etcd-key.pem snapshot save /backup/etcd/snapshot-$(printf \"%(%Y-%m-%d-%H:%M:%S_%Z)T\n\").db"]
          volumeMounts:
            - mountPath: /etc/etcd
              name: etcd-certs
              readOnly: true
            - mountPath: /backup/etcd
              subPath: etcd
              name: backup
      hostNetwork: true
      restartPolicy: Never
      tolerations:
        - effect: NoSchedule
          operator: Exists
      nodeSelector:
        etcd: "true"
      volumes:
        - name: etcd-certs
          hostPath:
            path: /etc/etcd
            type: Directory
        - name: backup
          persistentVolumeClaim:
            claimName: etcd-backups-nfs-pvc
