-
-
Save patrickdk77/86cb406b436368f4504be76306b57888 to your computer and use it in GitHub Desktop.
k8s cronjob for doing daily backups of etcd from a master. (updated)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| apiVersion: v1 | |
| kind: PersistentVolumeClaim | |
| metadata: | |
| name: etcd-backup | |
| namespace: kube-system | |
| spec: | |
| accessModes: | |
| - ReadWriteOnce | |
| volumeMode: Filesystem | |
| resources: | |
| requests: | |
| storage: 8Gi | |
| --- | |
| apiVersion: batch/v1 | |
| kind: CronJob | |
| metadata: | |
| name: etcd-backup | |
| namespace: kube-system | |
| spec: | |
| schedule: "8 7 * * *" | |
| successfulJobsHistoryLimit: 3 | |
| suspend: false | |
| concurrencyPolicy: Allow | |
| failedJobsHistoryLimit: 1 | |
| jobTemplate: | |
| spec: | |
| template: | |
| spec: | |
| containers: | |
| - args: | |
| - -c | |
| - etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt | |
| --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt --key=/etc/kubernetes/pki/etcd/healthcheck-client.key | |
| snapshot save /backup/etcd-snapshot_$(printf '%(%FT%T%z)T')_${HOSTNAME}.db | |
| command: | |
| - /bin/sh | |
| env: | |
| - name: ETCDCTL_API | |
| value: "3" | |
| image: registry.k8s.io/etcd:3.6.4-0 | |
| imagePullPolicy: IfNotPresent | |
| name: backup | |
| resources: {} | |
| terminationMessagePath: /dev/termination-log | |
| terminationMessagePolicy: File | |
| volumeMounts: | |
| - mountPath: /etc/kubernetes/pki/etcd | |
| name: etcd-certs | |
| readOnly: true | |
| - mountPath: /backup | |
| name: backup | |
| - args: | |
| - -c | |
| - ls -1 /backup/*.db | tail -n +30 | xargs rm | |
| command: | |
| - /bin/sh | |
| image: busybox:1.37.0 | |
| imagePullPolicy: IfNotPresent | |
| name: backup-purge | |
| volumeMounts: | |
| - mountPath: /backup | |
| name: backup | |
| dnsPolicy: ClusterFirst | |
| hostNetwork: true | |
| nodeSelector: | |
| node-role.kubernetes.io/control-plane: "" | |
| restartPolicy: OnFailure | |
| schedulerName: default-scheduler | |
| securityContext: {} | |
| terminationGracePeriodSeconds: 30 | |
| tolerations: | |
| - effect: NoSchedule | |
| operator: Exists | |
| volumes: | |
| - hostPath: | |
| path: /etc/kubernetes/pki/etcd | |
| type: DirectoryOrCreate | |
| name: etcd-certs | |
| - name: backup | |
| persistentVolumeClaim: | |
| claimName: etcd-backup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment