kubernetes etcd 备份

  运维

pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: etcd-bak
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: "500Gi"
  volumeName: 
  storageClassName: nfs

etcd备份 CronJob

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: etcd-disaster-recovery
spec:
 schedule: "0 22 * * *"
 jobTemplate:
  spec:
    template:
      metadata:
       labels:
        app: etcd-disaster-recovery
      spec:
        affinity:
          nodeAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
                  nodeSelectorTerms:
                  - matchExpressions:
                    - key: kubernetes.io/role
                      operator: In
                      values:
                      - master
        containers:
        - name: etcd
          #image: coreos/etcd:v3.0.17
          #image: registry.cn-hangzhou.aliyuncs.com/sre_pub/etcd:v3.3.8
          image: k8s.gcr.io/etcd:3.2.24
          command:
          - sh
          - -c
          - "export ETCDCTL_API=3; \
             etcdctl --endpoints $ENDPOINT snapshot save /snapshot/$(date +%Y%m%d_%H%M%S)_snapshot.db; \
             echo etcd backup sucess"
          env:
          - name: ENDPOINT
            value: "127.0.0.1:2379"
          volumeMounts:
            - mountPath: "/snapshot"
              name: snapshot
              subPath: data/etcd-snapshot
            - mountPath: /etc/localtime
              name: lt-config
            - mountPath: /etc/timezone
              name: tz-config
        restartPolicy: OnFailure
        volumes:
          - name: snapshot
            persistentVolumeClaim:
              claimName: etcd-bak
          - name: lt-config
            hostPath:
              path: /etc/localtime
          - name: tz-config
            hostPath:
              path: /etc/timezone
        hostNetwork: true

LEAVE A COMMENT

发表评论前,请选对水果【Apple=苹果、Banana=香蕉、Pineapple=菠萝、Grapes=葡萄】 Banana...