k8s 1.22 使用cronjob 备份etcd
编辑 backup-etcd.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
namespace: kube-system
name: etcd-backup
spec:
schedule: "0 18 * * *"
jobTemplate:
spec:
completions: 3
parallelism: 3
template:
metadata:
labels:
backup: "etcd"
spec:
containers:
- name: etcd-backup
image: registry.aliyuncs.com/google_containers/etcd:3.5.0-0
env:
- name: NODE_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
args:
- |
#!/bin/sh
set -ex
ETCDCTL_API=3 etcdctl --cert="/etc/kubernetes/pki/etcd/peer.crt" --key=/etc/kubernetes/pki/etcd/peer.key --cacert="/etc/kubernetes/pki/etcd/ca.crt" --endpoints=https://$NODE_IP:2379 snapshot save /backup/db
command:
- /bin/sh
- '-c'
volumeMounts:
- mountPath: /etc/kubernetes/pki/etcd
name: master-config
readOnly: true
- name: backup
mountPath: /backup
restartPolicy: OnFailure
tolerations:
- effect: NoSchedule
operator: Exists
nodeSelector:
node-role.kubernetes.io/master: ""
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "backup"
operator: In
values:
- "etcd"
topologyKey: "kubernetes.io/hostname"
volumes:
- hostPath:
path: /etc/kubernetes/pki/etcd/
type: ''
name: master-config
- name: backup
ephemeral:
volumeClaimTemplate:
metadata:
labels:
type: etcd-backup-volume
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "local-path"
resources:
requests:
storage: 1Gi
创建cronjob
kubectl apply -f backup-etcd.yaml
Last updated