美文网首页
k8s etcd定期defrag/snapshot

k8s etcd定期defrag/snapshot

作者: wwq2020 | 来源:发表于2023-10-09 06:46 被阅读0次

    定期defrag

    apiVersion: batch/v1
    kind: CronJob
    metadata:
      name: etcd-snapshot
      namespace: kube-system
    spec:
      concurrencyPolicy: Forbid
      failedJobsHistoryLimit: 1
      jobTemplate:
        metadata:
          creationTimestamp: null
        spec:
          completions: 3
          parallelism: 3
          template:
            metadata:
              creationTimestamp: null
              labels:
                app: etcd-snapshot
            spec:
              affinity:
                nodeAffinity:
                  requiredDuringSchedulingIgnoredDuringExecution:
                    nodeSelectorTerms:
                    - matchExpressions:
                      - key: node-role.kubernetes.io/master
                        operator: Exists
                podAntiAffinity:
                  - requiredDuringSchedulingIgnoredDuringExecution:
                      labelSelector:
                        matchLabels:
                          app: etcd-snapshot
                      namespaces:
                      - kube-system
                      topologyKey: kubernetes.io/hostname
              containers:
              - command:
                - sh
                - -c
                - ETCDCTL_API=3 etcdctl defrag --endpoints localhost:2379 --cert=/etc/kubernetes/pki/etcd/server.crt
                  --key=/etc/kubernetes/pki/etcd/server.key --cacert=/etc/kubernetes/pki/etcd/ca.crt
                image: registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.8
                imagePullPolicy: IfNotPresent
                name: etcd
                resources: {}
                terminationMessagePath: /dev/termination-log
                terminationMessagePolicy: File
                volumeMounts:
                - mountPath: /snapshot
                  name: snapshot
                  subPath: backup
                - mountPath: /etc/kubernetes
                  name: kubernetes
                - mountPath: /etc/localtime
                  name: lt-localtime
                - mountPath: /etc/timezone
                  name: timezone
              dnsPolicy: ClusterFirst
              hostNetwork: true
              restartPolicy: OnFailure
              schedulerName: default-scheduler
              securityContext: {}
              terminationGracePeriodSeconds: 30
              tolerations:
              - operator: Exists
              volumes:
              - hostPath:
                  path: /data
                  type: ""
                name: snapshot
              - hostPath:
                  path: /etc/localtime
                  type: ""
                name: localtime
              - hostPath:
                  path: /etc/timezone
                  type: ""
                name: timezone
              - hostPath:
                  path: /etc/kubernetes
                  type: ""
                name: kubernetes
      schedule: 0 */1 * * *
      successfulJobsHistoryLimit: 3
      suspend: false
    

    定期snapshot

    apiVersion: batch/v1
    kind: CronJob
    metadata:
      name: etcd-defrag
      namespace: kube-system
    spec:
      concurrencyPolicy: Forbid
      failedJobsHistoryLimit: 1
      jobTemplate:
        metadata:
          creationTimestamp: null
        spec:
          completions: 3
          parallelism: 3
          template:
            metadata:
              creationTimestamp: null
              labels:
                app: etcd-defrag
            spec:
              affinity:
                nodeAffinity:
                  requiredDuringSchedulingIgnoredDuringExecution:
                    nodeSelectorTerms:
                    - matchExpressions:
                      - key: node-role.kubernetes.io/master
                        operator: Exists
                podAntiAffinity:
                  - requiredDuringSchedulingIgnoredDuringExecution:
                      labelSelector:
                        matchLabels:
                          app: etcd-defrag
                      namespaces:
                      - kub-system
                      topologyKey: kubernetes.io/hostname
              containers:
              - command:
                - sh
                - -c
                - ETCDCTL_API=3 etcdctl snapshot save /snapshot/etcd_snapshot.db --endpoints localhost:2379
                  --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key
                  --cacert=/etc/kubernetes/pki/etcd/ca.crt
                image: registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.8
                imagePullPolicy: IfNotPresent
                name: etcd
                resources: {}
                terminationMessagePath: /dev/termination-log
                terminationMessagePolicy: File
                volumeMounts:
                - mountPath: /snapshot
                  name: snapshot
                  subPath: backup
                - mountPath: /etc/kubernetes
                  name: kubernetes
                - mountPath: /etc/localtime
                  name: lt-localtime
                - mountPath: /etc/timezone
                  name: timezone
              dnsPolicy: ClusterFirst
              hostNetwork: true
              restartPolicy: OnFailure
              schedulerName: default-scheduler
              securityContext: {}
              terminationGracePeriodSeconds: 30
              tolerations:
              - operator: Exists
              volumes:
              - hostPath:
                  path: /data
                  type: ""
                name: snapshot
              - hostPath:
                  path: /etc/localtime
                  type: ""
                name: localtime
              - hostPath:
                  path: /etc/timezone
                  type: ""
                name: timezone
              - hostPath:
                  path: /etc/kubernetes
                  type: ""
                name: kubernetes
      schedule: 0 */1 * * *
      successfulJobsHistoryLimit: 3
      suspend: false
    

    相关文章

      网友评论

          本文标题:k8s etcd定期defrag/snapshot

          本文链接:https://www.haomeiwen.com/subject/ebgbbdtx.html