apiVersion: batch.kubesphere.io/v1alpha1
kind: Job
metadata:
name: etcd-backup
namespace: default
spec:
jobConfiguration:
tasks:
- name: backup-etcd
image: bitnami/etcd:3.5.0
command:
- /bin/bash
- -ce
- |
ETCD_ENDPOINTS=$(echo "https://"$(kubectl get svc etcd-headless -n kube-system -o jsonpath='{.spec.clusterIP}'):2379)
ETCD_CA_CERT=/opt/bitnami/etcd/certs/etcd-ca.crt
ETCD_CERT=/opt/bitnami/etcd/certs/etcd.crt
ETCD_KEY=/opt/bitnami/etcd/certs/etcd.key
BACKUP_DIR=/backup
mkdir -p $BACKUP_DIR
/opt/bitnami/etcd/bin/etcdctl --endpoints=$ETCD_ENDPOINTS --cacert=$ETCD_CA_CERT --cert=$ETCD_CERT --key=$ETCD_KEY snapshot save $BACKUP_DIR/snapshot.db
volumeMounts:
- name: etcd-certs
mountPath: /opt/bitnami/etcd/certs
- name: backup-volume
mountPath: /backup
volumes:
- name: etcd-certs
configMap:
name: etcd-certs
- name: backup-volume
hostPath:
path: /path/to/your/backup/directory
type: DirectoryOrCreate