Velero - 还原备份时,卷快照不包含任何数据

Velero - Volume Snapshots contain no data when restoring a backup

提问人:Chesneycar 提问时间:3/21/2023 更新时间:11/3/2023 访问量:2207

问:

我想使用 Velero 将应用程序备份到 minio 存储桶。下面是一些上下文,我有 2 个 AKS 群集 [dev、tools]。

tools 集群运行我的 minio 实例,dev 是我的工作负载集群。

我在互联网上下载了一些示例,了解如何使用 helm 安装 Velero,以及如何配置它以将 worloads 备份到 minio。

现在,我可以用它的 PersistentVolume 对应用程序进行备份,但是当我进行还原时,卷中没有数据。我将在下面详细介绍,我感谢社区为解决这个问题提供的任何建议或帮助。

以下是我遵循的步骤:

  1. 安装 Velero :
helm repo add vmware-tanzu https://vmware-tanzu.github.io/helm-charts
helm repo update
helm upgrade --install $RELEASE_NAME vmware-tanzu/velero \ 
  --namespace $NAMESPACE --create-namespace -f $VALUES_FILE
  1. 这是我使用的 helm values.yaml 文件的摘录,其中包含最重要的部分:
initContainers:
    - name: velero-plugin-for-aws
      image: velero/velero-plugin-for-aws:v1.6.1
      imagePullPolicy: IfNotPresent
      volumeMounts:
        - mountPath: /target
          name: plugins

  configuration:
    plugins:
      aws:
        image: velero/velero-plugin-for-aws:v1.2.0
      minio:
        image: velero/velero-plugin-for-minio:v1.2.0
  
    provider: aws
  
    backupStorageLocation:
      name: default 
      bucket: dev-velero-backup
      config:
        region: minio
        s3ForcePathStyle: "true"
        publicUrl: http://dev.api
        s3Url: "minio.tenant"
        insecureSkipTLSVerify: true
    
    volumeSnapshotLocation:
      region: minio
      name: default
      provider: aws
      config:
        region: minio
  
  # specify the credentials for minio.
  credentials:
    useSecret: true
    existingSecret: ""
    secretContents:
      cloud: |
        [default]
        aws_access_key_id = minio
        aws_secret_access_key = minio
      s3: ""
  
    features:
    namespace: velero
  backupsEnabled: true
  snapshotsEnabled: true
  1. 当我运行 backup 命令时,我可以看到在 minio 存储桶中创建的对象,因此 velero 和 minio 之间的通信没有问题。

  2. 这是我用来备份我的nginx-example应用程序的命令:velero backup create nginx-example --include-namespaces nginx-example --snapshot-volumes

备份完成,没有任何错误。

以下是备份中的日志:

time="2023-03-21T13:11:28Z" level=info msg="Executing RemapCRDVersionAction" backup=velero/nginx-example cmd=/velero logSource="pkg/backup/remap_crd_version_action.go:61" pluginName=velero
time="2023-03-21T13:11:28Z" level=info msg="Exiting RemapCRDVersionAction, the cluster does not support v1beta1 CRD" backup=velero/nginx-example cmd=/velero logSource="pkg/backup/remap_crd_version_action.go:89" pluginName=velero
time="2023-03-21T13:11:28Z" level=info msg="Backed up a total of 24 items" backup=velero/nginx-example logSource="pkg/backup/backup.go:413" progress=
  1. 下一步是模拟 DR 事件,方法是删除 nginx-example 命名空间并验证应用的所有 k8s 资源(包括 PV)是否被销毁。

kubectl delete ns nginx-example #Wait, and Check if pv is deleted.

  1. 当我尝试从velero备份中恢复nginx-example时,通过运行以下命令:

velero restore create --from-backup nginx-example --include-namespaces nginx-example --restore-volumes

我可以在还原日志中看到以下消息:

velero restore logs nginx-example-20230321141504
time="2023-03-21T13:15:06Z" level=info msg="Waiting for all post-restore-exec hooks to complete" logSource="pkg/restore/restore.go:596" restore=velero/nginx-example-20230321141504
time="2023-03-21T13:15:06Z" level=info msg="Done waiting for all post-restore exec hooks to complete" logSource="pkg/restore/restore.go:604" restore=velero/nginx-example-20230321141504
time="2023-03-21T13:15:06Z" level=info msg="restore completed" logSource="pkg/controller/restore_controller.go:545" restore=velero/nginx-example-20230321141504
  1. 当我验证 nginx acess-logs 是否仍然包含以前访问的数据时,它是空的:

kubectl exec -it nginx-deploy-bf489bc5-8jrtz -- cat /var/log/nginx/access.log

nginx-example 应用程序在 PV 上挂载路径。/var/log/nginx

    spec:
      volumes:
        - name: nginx-logs
          persistentVolumeClaim:
           claimName: nginx-logs
      containers:
      - image: nginx:stable
        name: nginx
        ports:
        - containerPort: 80
        volumeMounts:
          - mountPath: "/var/log/nginx"
            name: nginx-logs
            readOnly: false

最终目标应该是使用包含访问日志数据的持久卷成功备份和还原 nginx-example 应用程序。

如果这个问题可以在您的帮助下得到解决,我会非常高兴,当然我会提供任何相关信息。

其他信息

  1. VolumeSnapshotLocation
apiVersion: velero.io/v1
kind: VolumeSnapshotLocation
metadata:
  annotations:
    helm.sh/hook: post-install,post-upgrade,post-rollback
    helm.sh/hook-delete-policy: before-hook-creation
  creationTimestamp: "2023-03-21T01:26:37Z"
  generation: 1
  labels:
    app.kubernetes.io/instance: velero-ontwikkel
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: velero
    helm.sh/chart: velero-3.1.4
  name: default
  namespace: velero
  resourceVersion: "83378185"
  uid: cea663dd-c1d9-4035-8c84-79a240f4351c
spec:
  config:
    region: minio
  provider: aws
  1. 已安装的 velero 插件
NAME                                        KIND
velero.io/crd-remap-version                 BackupItemAction
velero.io/pod                               BackupItemAction
velero.io/pv                                BackupItemAction
velero.io/service-account                   BackupItemAction
velero.io/aws                               ObjectStore
velero.io/add-pv-from-pvc                   RestoreItemAction
velero.io/add-pvc-from-pod                  RestoreItemAction
velero.io/admission-webhook-configuration   RestoreItemAction
velero.io/apiservice                        RestoreItemAction
velero.io/change-pvc-node-selector          RestoreItemAction
velero.io/change-storage-class              RestoreItemAction
velero.io/cluster-role-bindings             RestoreItemAction
velero.io/crd-preserve-fields               RestoreItemAction
velero.io/init-restore-hook                 RestoreItemAction
velero.io/job                               RestoreItemAction
velero.io/pod                               RestoreItemAction
velero.io/pod-volume-restore                RestoreItemAction
velero.io/role-bindings                     RestoreItemAction
velero.io/service                           RestoreItemAction
velero.io/service-account                   RestoreItemAction
velero.io/aws                               VolumeSnapshotter

Kubernetes 备份 Minio 灾难恢复 velero

评论


答:

1赞 SikiShen 3/22/2023 #1

您可能需要启用 NodeAgent 进行卷备份,在 helm values.yaml 中添加 deployNodeAgent: true,以及备份何时使用选项 --default-volumes-to-fs-backup(就像旧版本使用选项 --default-volumes-to-restic)。

velero backup create backup-test --include-namespaces nginx-example --default-volumes-to-fs-backup --snapshot-volumes --ttl 180h

完成备份后,您可以使用 --details 进行描述,您可能会找到如下所示的内容,您将知道卷备份成功。 velero backup 描述 backup-test --details

kopia Backups:
  Completed:
    nginx-example/nginx-deployment-5b47dbff44-cw9l4: nginx-logs

评论

0赞 Chesneycar 3/22/2023
多亏了@SikiShen,我错过了那面旗帜。我能够使用持久卷成功备份命名空间中的资源。在销毁资源并从备份中执行还原后,我可以验证数据是否存在。--default-volumes-to-fs-backup
0赞 Chesneycar 3/22/2023
有点跑题了,但是我该如何进行增量备份呢?我已经对命名空间进行了备份,当我执行另一个备份时,我收到另一个备份已存在的消息。@SikiShen
1赞 SikiShen 3/22/2023
@Chesneycar,应该通过计划备份来工作,只要存在一个未过期的备份,Kopia 实际上就会进行增量备份。
1赞 SikiShen 3/22/2023
@Chesneycar我确实问过他们同样的问题,哈哈,github.com/vmware-tanzu/velero/discussions/6000,他们并没有在文档中明确说明增量。
1赞 Chesneycar 3/23/2023
我在 helm chart values 文件中看到您可以设置为 true,然后您不必指定标志。defaultVolumesToFsBackup--default-volumes-fs-backup