-
-
Save shakahl/432bef2e53543d2ef3f9061ad063536f to your computer and use it in GitHub Desktop.
k8s cronjob for doing daily backups of etcd from a master.
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/v1beta1 | |
kind: CronJob | |
metadata: | |
name: etcd-backup | |
namespace: kube-system | |
spec: | |
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-$(date +%Y%m%d_%H%M%S_%Z).db | |
command: | |
- /bin/sh | |
env: | |
- name: ETCDCTL_API | |
value: "3" | |
image: k8s.gcr.io/etcd-amd64:3.3.15 | |
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 | |
- find /backup -type f -mtime +30 -name '*.db' -exec rm -- '{}' \; | |
command: | |
- /bin/sh | |
image: busybox:1.31.1 | |
imagePullPolicy: IfNotPresent | |
name: backup-purge | |
volumeMounts: | |
- mountPath: /backup | |
name: backup | |
dnsPolicy: ClusterFirst | |
hostNetwork: true | |
nodeSelector: | |
node-role.kubernetes.io/master: "" | |
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 | |
schedule: "0 7 * * *" | |
successfulJobsHistoryLimit: 3 | |
suspend: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment