Skip to content

1.etcd备份

bash
$ vim etcd-backup-cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: etcd-backup-cronjob
  namespace: default
spec:
 schedule: "* * * * *"    # 为了测试改为每分钟执行备份
 jobTemplate:
  spec:
    template:
      metadata:
       labels:
        app: etcd-backup-cronjob
      spec:
        containers:
        - name: etcd
          image: docker.io/bitnami/etcd:3.5.4-debian-10-r25
          command:
          - sh
          - -c
          - "etcdctl --endpoints $ENDPOINT --user $USER:$PASSWORD snapshot save /snapshot/$(date +%Y%m%d_%H%M%S)_snapshot.db"
          env:
          - name: USER     # etcd 用户
            value: root
          - name: PASSWORD  # etcd 用户密码
            value: qYKH9wUBch
          - name: ENDPOINT
            value: "192.168.1.12:32379"  # ETCD的客户端地址
          volumeMounts:
            - mountPath: "/snapshot"
              name: snapshot
              subPath: data/etcd-snapshot
        restartPolicy: OnFailure
        volumes:
          - name: snapshot
            persistentVolumeClaim:
              claimName: etcd-backup-pvc    # 指定创建好的PVC
        hostNetwork: true
$ vim etcd-backup-cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: etcd-backup-cronjob
  namespace: default
spec:
 schedule: "* * * * *"    # 为了测试改为每分钟执行备份
 jobTemplate:
  spec:
    template:
      metadata:
       labels:
        app: etcd-backup-cronjob
      spec:
        containers:
        - name: etcd
          image: docker.io/bitnami/etcd:3.5.4-debian-10-r25
          command:
          - sh
          - -c
          - "etcdctl --endpoints $ENDPOINT --user $USER:$PASSWORD snapshot save /snapshot/$(date +%Y%m%d_%H%M%S)_snapshot.db"
          env:
          - name: USER     # etcd 用户
            value: root
          - name: PASSWORD  # etcd 用户密码
            value: qYKH9wUBch
          - name: ENDPOINT
            value: "192.168.1.12:32379"  # ETCD的客户端地址
          volumeMounts:
            - mountPath: "/snapshot"
              name: snapshot
              subPath: data/etcd-snapshot
        restartPolicy: OnFailure
        volumes:
          - name: snapshot
            persistentVolumeClaim:
              claimName: etcd-backup-pvc    # 指定创建好的PVC
        hostNetwork: true