paas管理平台

使用velero备份恢复k8s集群

2021-09-28  本文已影响0人  行者深蓝

Velero 组件

Velero 组件一共分两部分,分别是客户端和服务端。

Velero客户端安装

部署在k8s master节点,或者安装有kubectl命令,包含对应集群 kubeconfig 配置的机器上

wget https://github.com/vmware-tanzu/velero/releases/download/v1.6.3/velero-v1.6.3-linux-amd64.tar.gz
tar zxvf velero-v1.6.3-linux-amd64.tar.gz
mv velero-v1.6.3-linux-amd64/velero /usr/local/bin/

Velero服务端安装

创建一个兼容S3协议的对象存储, 记录对应的

  1. bucket name
  2. region
  3. AK/SK
  4. endpoint
kubectl create namespace velero
kubectl create secret docker-registry registry-velero-secret \
        --namespace=velero \
        --docker-server=uhub.service.ucloud.cn/ucloud_pts \
        --docker-username='xxxxxx' \
        --docker-password='xxxxxx'

helm repo add vmware-tanzu https://vmware-tanzu.github.io/helm-charts
helm repo update

cat > velero-values.yaml << EOF
image:
  repository: uhub.service.ucloud.cn/ucloud_pts/velero
  tag: v1.6.3
  imagePullSecrets: 
    - name: registry-velero-secret
credentials:
  useSecret: true
  secretContents:
    cloud: |
      [default]
      aws_access_key_id=<AWS_ACCESS_KEY_ID>
      aws_secret_access_key=<AWS_SECRET_ACCESS_KEY>
configuration:
  features:
    - EnableCSI
  provider: aws
  backupStorageLocation:
    name: default
    bucket: velero
    config:
      region: <region_zone_name>
      s3ForcePathStyle: true
      s3Url: http://<bucket-endpoint-domain>
      publicUrl: http://<bucket-endpoint-domain>
  volumeSnapshotLocation:
    name: default
    config:
      region: <region_zone_name>
      s3ForcePathStyle: true
      s3Url: http://<bucket-endpoint-domain>
      publicUrl: http://<bucket-endpoint-domain>
initContainers:
  - name: velero-plugin-for-aws
    image: velero/velero-plugin-for-aws:v1.2.0
    imagePullPolicy: IfNotPresent
    volumeMounts:
      - mountPath: /target
        name: plugins
backupsEnabled: true
snapshotsEnabled: true
deployRestic: true
configMaps:
  restic-restore-action-config:
    labels:
      velero.io/plugin-config: ""
      velero.io/restic: RestoreItemAction
    data:
      image: uhub.service.ucloud.cn/ucloud_pts/velero-restic-restore-helper:v1.6.3 
metrics:
  enabled: true
  serviceMonitor:
    enabled: true
    additionalLabels:
      release: prometheus
EOF

helm upgrade --install velero vmware-tanzu/velero \
--namespace velero \
--create-namespace \
-f velero-values.yaml

备份参考

使用 Restic 给带有 PV 的 Pod 进行备份,必须先给 Pod 加上注解

kubectl  get pvc -n monitor 
kubectl  -n monitor annotate pod/grafana-674899bc9f-rnz5h backup.velero.io/backup-volumes=grafana-pv-xxxxx
velero backup create gitlab-backup --snapshot-volumes=false --include-namespaces monitor

注意事项

参考

上一篇 下一篇

猜你喜欢

热点阅读