Velero 系列文章(一):基礎(chǔ)

概述

Velero 是一個(gè)開(kāi)源工具,可以安全地備份和還原,執(zhí)行災(zāi)難恢復(fù)以及遷移 Kubernetes 集群資源和持久卷。

災(zāi)難恢復(fù)

Velero 可以在基礎(chǔ)架構(gòu)丟失,數(shù)據(jù)損壞和/或服務(wù)中斷的情況下,減少恢復(fù)時(shí)間。

數(shù)據(jù)遷移

Velero 通過(guò)輕松地將 Kubernetes 資源從一個(gè)集群遷移到另一個(gè)集群來(lái)實(shí)現(xiàn)集群可移植性

數(shù)據(jù)保護(hù)

提供關(guān)鍵數(shù)據(jù)保護(hù)功能,例如定時(shí)計(jì)劃的備份,保留計(jì)劃以及自定義操作的備份前或備份后鉤子。

備份集群

使用 namespace resources 或 label selector 備份整個(gè)集群或部分集群的 Kubernetes 資源和卷。

定期備份

設(shè)置計(jì)劃以定期間隔自動(dòng)啟動(dòng)備份。

備份鉤子

配置備份前和備份后鉤子,以在 Velero 備份之前和之后執(zhí)行自定義操作。

安裝 - 基本安裝

前提

  • 在啟用 DNS 和容器聯(lián)網(wǎng)的情況下訪問(wèn) Kubernetes 集群 v1.16 或更高版本。
  • kubectl本地安裝

Velero 使用對(duì)象存儲(chǔ)來(lái)存儲(chǔ)備份和關(guān)聯(lián)的工件。 它還可以選擇與受支持的塊存儲(chǔ)系統(tǒng)集成,以對(duì)您的持久卷進(jìn)行快照。 在開(kāi)始安裝過(guò)程之前,您應(yīng)該從 兼容的提供程序列表 中識(shí)別將要使用的對(duì)象存儲(chǔ)提供程序和可選的塊存儲(chǔ)提供程序。

Velero 支持云提供商環(huán)境和本地環(huán)境的存儲(chǔ)提供商。 有關(guān)內(nèi)部部署方案的更多詳細(xì)信息,請(qǐng)參見(jiàn) 內(nèi)部部署文檔

安裝 CLI

  1. 下載適用于您的客戶端平臺(tái)的 最新版本 的 tarball。
  2. 解壓 tarball: tar -xvf <RELEASE-TARBALL-NAME>.tar.gz
  3. 將解壓后的velero放到$PATH(一般是/usr/local/bin)

安裝配置 server 端組件

有兩種支持的方法來(lái)安裝 Velero 服務(wù)器組件:

Velero 使用存儲(chǔ)提供程序插件與各種存儲(chǔ)系統(tǒng)集成,以支持備份和快照操作。 安裝和配置 Velero 服務(wù)器組件以及相應(yīng)插件的步驟特定于您選擇的存儲(chǔ)提供商。 要查找您選擇的存儲(chǔ)提供商的安裝說(shuō)明,請(qǐng)?jiān)?支持的存儲(chǔ)提供商 頁(yè)面上訪問(wèn)提供商的文檔鏈接。

?? 注意:

如果您的對(duì)象存儲(chǔ)提供程序與卷快照提供程序不同,請(qǐng)首先按照對(duì)象存儲(chǔ)提供程序的安裝說(shuō)明進(jìn)行操作,然后返回此處并按照說(shuō)明添加 卷快照提供程序。

命令行自動(dòng)補(bǔ)全

https://velero.io/docs/v1.8/customize-installation/#enabling-shell-autocompletion

安裝 - 定制化安裝

https://velero.io/docs/v1.8/customize-installation/

安裝 - 提供商

Velero 支持各種存儲(chǔ)提供程序,以進(jìn)行不同的備份和快照操作。 Velero 有一個(gè)插件系統(tǒng),它允許任何人在不修改 Velero 代碼庫(kù)的情況下增加對(duì)其他備份和卷存儲(chǔ)平臺(tái)的兼容性。

Velero 支持的提供商

提供商 對(duì)象存儲(chǔ) 卷快照 插件提供商 Repo 安裝說(shuō)明
Amazon Web Services (AWS) AWS S3 AWS EBS Velero plugin for AWS AWS Plugin Setup
Google Cloud Platform (GCP) Google Cloud Storage Google Compute Engine Disks Velero plugin for GCP GCP Plugin Setup
Microsoft Azure Azure Blob Storage Azure Managed Disks Velero plugin for Microsoft Azure Azure Plugin Setup
VMware vSphere ?? vSphere Volumes VMware vSphere vSphere Plugin Setup
Container Storage Interface (CSI) ?? CSI Volumes Velero plugin for CSI CSI Plugin Setup

社區(qū)支持的提供商

Provider Object Store Volume Snapshotter Plugin Documentation Contact
AlibabaCloud Alibaba Cloud OSS Alibaba Cloud AlibabaCloud GitHub Issue
DigitalOcean DigitalOcean Object Storage DigitalOcean Volumes Block Storage StackPointCloud
Hewlett Packard ?? HPE Storage Hewlett Packard Slack, GitHub Issue
OpenEBS ?? OpenEBS CStor Volume OpenEBS Slack, GitHub Issue
OpenStack Swift Cinder OpenStack GitHub Issue
Portworx ?? Portworx Volume Portworx Slack, GitHub Issue
Storj Storj Object Storage ?? Storj GitHub Issue

與 s3 兼容的對(duì)象存儲(chǔ)提供程序

Velero 的 AWS Object Store 插件使用 Amazon 的 Go SDK 連接到 AWS S3 API。 一些第三方存儲(chǔ)提供程序也支持 S3 API,并且用戶報(bào)告了以下提供程序可用于 Velero:

?? 請(qǐng)注意,Velero 團(tuán)隊(duì)并未定期測(cè)試這些存儲(chǔ)提供商。

某些存儲(chǔ)提供程序(例如 Quobyte)可能需要不同的簽名算法版本。

安裝 - 快速驗(yàn)證安裝

  1. 在您的本地目錄中創(chuàng)建特定于 Velero 的憑證文件(credentials-velero):

    [default]
    aws_access_key_id = minio
    aws_secret_access_key = minio123
    
  2. 啟動(dòng)服務(wù)器和存儲(chǔ)服務(wù)。 在 Velero 目錄中,運(yùn)行:

    oc apply -f examples/minio/00-minio-deployment.yaml
    velero install \
        --provider aws \
        --plugins velero/velero-plugin-for-aws:v1.4.1 \
        --bucket velero \
        --secret-file ./credentials-velero \
        --use-volume-snapshots=false \
        --backup-location-config region=minio,s3ForcePathStyle="true",s3Url=http://minio.velero.svc:9000 
    

    此示例假定它在本地群集中運(yùn)行,而沒(méi)有能夠提供快照的卷提供程序,因此不會(huì)創(chuàng)建 VolumeSnapshotLocation(``--use-volume-snapshots=false`)。

    此外,您可以指定--use-restic啟用 RESTIC 支持,并指定--wait等待部署準(zhǔn)備就緒。

    對(duì)于更復(fù)雜的安裝需求,請(qǐng)使用 Helm Chart,或添加--dry-run -o yaml選項(xiàng)來(lái)生成安裝的 YAML 文件。

創(chuàng)建的內(nèi)容包括:

CustomResourceDefinition/backups.velero.io: attempting to create resource
CustomResourceDefinition/backups.velero.io: created
CustomResourceDefinition/backupstoragelocations.velero.io: attempting to create resource
CustomResourceDefinition/backupstoragelocations.velero.io: created
CustomResourceDefinition/deletebackuprequests.velero.io: attempting to create resource
CustomResourceDefinition/deletebackuprequests.velero.io: created
CustomResourceDefinition/downloadrequests.velero.io: attempting to create resource
CustomResourceDefinition/downloadrequests.velero.io: created
CustomResourceDefinition/podvolumebackups.velero.io: attempting to create resource
CustomResourceDefinition/podvolumebackups.velero.io: created
CustomResourceDefinition/podvolumerestores.velero.io: attempting to create resource
CustomResourceDefinition/podvolumerestores.velero.io: created
CustomResourceDefinition/resticrepositories.velero.io: attempting to create resource
CustomResourceDefinition/resticrepositories.velero.io: created
CustomResourceDefinition/restores.velero.io: attempting to create resource
CustomResourceDefinition/restores.velero.io: created
CustomResourceDefinition/schedules.velero.io: attempting to create resource
CustomResourceDefinition/schedules.velero.io: created
CustomResourceDefinition/serverstatusrequests.velero.io: attempting to create resource
CustomResourceDefinition/serverstatusrequests.velero.io: created
CustomResourceDefinition/volumesnapshotlocations.velero.io: attempting to create resource
CustomResourceDefinition/volumesnapshotlocations.velero.io: created
Waiting for resources to be ready in cluster...
Namespace/velero: attempting to create resource
Namespace/velero: already exists, proceeding
Namespace/velero: created
ClusterRoleBinding/velero: attempting to create resource
ClusterRoleBinding/velero: created
ServiceAccount/velero: attempting to create resource
ServiceAccount/velero: created
Secret/cloud-credentials: attempting to create resource
Secret/cloud-credentials: created
BackupStorageLocation/default: attempting to create resource
BackupStorageLocation/default: created
Deployment/velero: attempting to create resource
Deployment/velero: created
Velero is installed! ? Use 'kubectl logs deployment/velero -n velero' to view the status.

備份

  1. 為與app=iperf3-serverlabel selector 匹配的任何對(duì)象創(chuàng)建備份:

    velero backup create test-backup --selector app=iperf3-server
    

    或者,如果要備份除匹配標(biāo)簽backup=ignore的對(duì)象以外的所有對(duì)象,請(qǐng)執(zhí)行以下操作:

    velero backup create nginx-backup --selector 'backup!=ignore'
    
  2. (可選)使用app=iperf3-serverlabel selector 基于 cron 表達(dá)式創(chuàng)建定期計(jì)劃的備份:

    velero schedule create test-daily --schedule="0 1 * * *" --selector app=iperf3-server
    

    另外,您可以使用一些非標(biāo)準(zhǔn)的速記 cron 表達(dá)式:

    velero schedule create test-daily --schedule="@every 24h" --selector app=iperf3-server
    

    有關(guān)更多用法示例,請(qǐng)參見(jiàn) cron 軟件包 的文檔。

恢復(fù)

  1. 運(yùn)行:

    velero restore create --from-backup test-backup
    
  2. 運(yùn)行:

    velero restore get
    

    恢復(fù)完成后,輸出如下所示:

    NAME                          BACKUP         STATUS      WARNINGS   ERRORS    CREATED                         SELECTOR
    nginx-backup-20170727200524   nginx-backup   Completed   0          0         2017-07-27 20:05:24 +0000 UTC   <none>
    

如果有錯(cuò)誤或警告,則可以詳細(xì)查看它們:

velero restore describe <RESTORE_NAME>

清理

如果要?jiǎng)h除創(chuàng)建的所有備份,包括對(duì)象存儲(chǔ)中的數(shù)據(jù)和永久卷快照,則可以運(yùn)行:

velero backup delete BACKUP_NAME

這要求 Velero 服務(wù)器刪除與BACKUP_NAME相關(guān)聯(lián)的所有備份數(shù)據(jù)。 您需要對(duì)要永久刪除的每個(gè)備份執(zhí)行此操作。 Velero 的未來(lái)版本將允許您通過(guò)名稱或 label selector 刪除多個(gè)備份。

要從 Kubernetes 集群中完全卸載 Velero:

oc delete namespace/velero clusterrolebinding/velero
oc delete crds -l component=velero

安裝 - Restic 集成

Velero 支持使用稱為 restic 的免費(fèi)開(kāi)源備份工具備份和還原 Kubernetes 卷。 此支持被視為 Beta 質(zhì)量。 請(qǐng)查看 限制 列表,以了解它是否適合您的用例。

添加了 Restic 集成,為您提供了一個(gè)現(xiàn)成的解決方案,用于備份和還原幾乎任何類型的 Kubernetes 卷。 這種集成是 Velero 功能的補(bǔ)充,而不是現(xiàn)有功能的替代。 但是,如果您需要為存儲(chǔ)平臺(tái)使用卷快照插件,或者使用的是 EFS,AzureFile,NFS,emptyDir,local 或任何其他沒(méi)有本機(jī)快照概念的卷類型,restic 可能適合您 。

Restic 并不局限于特定的存儲(chǔ)平臺(tái),這意味著該集成還為將來(lái)實(shí)現(xiàn)跨卷類型數(shù)據(jù)遷移的工作鋪平了道路。

?? 注意:

不支持 hostPath 卷,但是支持 本地卷類型。

安裝 restic

前提

安裝 restic

要安裝 restic,請(qǐng)使用velero install命令中的--use-restic 標(biāo)志。 有關(guān)安裝命令的其他標(biāo)志的更多詳細(xì)信息,請(qǐng)參見(jiàn) 安裝概述

velero install --use-restic

在不支持快照的 Velero 支持的存儲(chǔ)提供程序上使用 Restic 時(shí),--use-volume-snapshots = false 標(biāo)志可防止在安裝時(shí)創(chuàng)建未使用的VolumeSnapshotLocation 。

配置 Restic DaemonSet Spec

安裝后,某些基于 Kubernetes 的 PaaS / CaaS 平臺(tái)也需要修改 Restic DaemonSet 規(guī)范。 僅當(dāng)您在 RancherOS,OpenShift,VMware Tanzu Kubernetes Grid Integrated Edition(以前稱為 VMware Enterprise PKS)或 Micrsoft Azure 上安裝時(shí),才需要本節(jié)中的步驟。

OpenShift

要將正確的主機(jī)路徑安裝到 Pod 卷,請(qǐng)?jiān)?code>privileged模式下運(yùn)行 Restic Pod。

  1. veleroServiceAccount 添加到privilegedSCC:

    $ oc adm policy add-scc-to-user privileged -z velero -n velero
    
  2. 對(duì)于 OpenShift 版本> = 4.1,修改 DaemonSet yaml 以請(qǐng)求privileged模式:

    @@ -67,3 +67,5 @@ spec:
                  value: /credentials/cloud
                - name: VELERO_SCRATCH_DIR
                  value: /scratch
    +          securityContext:
    +            privileged: true
    

    或:

    oc patch ds/restic \
      --namespace velero \
      --type json \
      -p '[{"op":"add","path":"/spec/template/spec/containers/0/securityContext","value": { "privileged": true}}]'
    

如果 restic 不在特權(quán)模式下運(yùn)行,則由于主機(jī)系統(tǒng)級(jí)別配置了默認(rèn)的強(qiáng)制實(shí)施 SELinux 模式,它將無(wú)法訪問(wèn)已掛載的 hostpath 目錄內(nèi)的 pod 卷。 您可以 創(chuàng)建自定義 SCC 來(lái)放松群集中的安全性,以便允許 Restic Pod 使用 hostPath 卷插件,而無(wú)需授予它們?cè)L問(wèn)privilegedSCC 的權(quán)限。

默認(rèn)情況下,用戶維度的 openshift 名稱空間不會(huì)在集群中的所有節(jié)點(diǎn)上調(diào)度 Pod。

要在所有節(jié)點(diǎn)上計(jì)劃名稱空間,需要一個(gè)注釋:

oc annotate namespace <velero namespace> openshift.io/node-selector=""

這應(yīng)該在安裝 velero 之前完成。

或需要?jiǎng)h除并重新創(chuàng)建 ds:

oc get ds restic -o yaml -n <velero namespace> > ds.yaml
oc annotate namespace <velero namespace> openshift.io/node-selector=""
oc create -n <velero namespace> -f ds.yaml

備份

Velero 支持發(fā)現(xiàn)需要使用 Restic 備份的 Pod 卷的兩種方法:

  • 選擇性啟用方式:每個(gè)包含要使用 Restic 備份的卷的 Pod 都必須標(biāo)有卷的名稱。

  • 選擇性退出方式:使用 Restic 備份所有 Pod 卷,并具有退出任何不應(yīng)備份的卷的功能。

以下各節(jié)提供了有關(guān)這兩種方法的更多詳細(xì)信息。

選擇性退出方式

在這種方法中,Velero 將使用 restic 備份所有 pod 卷,但以下情況除外:

  • 安裝默認(rèn)服務(wù)帳戶令牌,kubernetes secrets 和 config maps 的卷
  • Hostpath 卷

使用 pod 上的backup.velero.io/backup-volumes-excludes注釋可以排除卷不被備份的情況。

使用此方法進(jìn)行備份的說(shuō)明如下:

  1. 在包含不應(yīng)使用 Restic 備份的卷的每個(gè) Pod 上運(yùn)行以下命令

    kubectl -n YOUR_POD_NAMESPACE annotate pod/YOUR_POD_NAME backup.velero.io/backup-volumes-excludes=YOUR_VOLUME_NAME_1,YOUR_VOLUME_NAME_2,...
    

    其中,卷名是容器規(guī)范中卷的名稱。

    例如,在以下 pod 中:

    apiVersion: v1
    kind: Pod
    metadata:
      name: app1
      namespace: sample
    spec:
      containers:
      - image: k8s.gcr.io/test-webserver
        name: test-webserver
        volumeMounts:
        - name: pvc1-vm
          mountPath: /volume-1
        - name: pvc2-vm
          mountPath: /volume-2
      volumes:
      - name: pvc1-vm
        persistentVolumeClaim:
          claimName: pvc1
      - name: pvc2-vm
          claimName: pvc2
    

    要排除卷pvc1-vm的 Restic 備份,應(yīng)運(yùn)行:

    kubectl -n sample annotate pod/app1 backup.velero.io/backup-volumes-excludes=pvc1-vm
    
  2. 進(jìn)行 Velero 備份:

    velero backup create BACKUP_NAME --default-volumes-to-restic OTHER_OPTIONS
    

    以上步驟在每個(gè)備份的基礎(chǔ)上使用了選擇性退出方法。

    或者,可以在運(yùn)行帶有--default-volumes-to-restic 標(biāo)志的velero install命令的所有 velero 備份上啟用此行為。 有關(guān)詳細(xì)信息,請(qǐng)參閱 安裝概述

  3. 備份完成后,查看有關(guān)備份的信息:

    velero backup describe YOUR_BACKUP_NAME
    kubectl -n velero get podvolumebackups -l velero.io/backup-name=YOUR_BACKUP_NAME -o yaml
    

選擇性啟用方式

默認(rèn)情況下,Velero 使用這種方法來(lái)發(fā)現(xiàn)需要使用 Restic 備份的 Pod 卷,其中每個(gè)包含要使用 Restic 備份的卷的 Pod 都必須標(biāo)有該卷的名稱。

使用此方法進(jìn)行備份的說(shuō)明如下:

  1. 對(duì)包含要備份的卷的每個(gè) Pod 運(yùn)行以下命令:

    kubectl -n YOUR_POD_NAMESPACE annotate pod/YOUR_POD_NAME backup.velero.io/backup-volumes=YOUR_VOLUME_NAME_1,YOUR_VOLUME_NAME_2,...
    

    其中,卷名是容器 spec 中卷的名稱。

    例如,對(duì)于以下 pod:

    apiVersion: v1
    kind: Pod
    metadata:
      name: sample
      namespace: foo
    spec:
      containers:
      - image: k8s.gcr.io/test-webserver
        name: test-webserver
        volumeMounts:
        - name: pvc-volume
          mountPath: /volume-1
        - name: emptydir-volume
          mountPath: /volume-2
      volumes:
      - name: pvc-volume
        persistentVolumeClaim:
          claimName: test-volume-claim
      - name: emptydir-volume
        emptyDir: {}
    

    你應(yīng)該運(yùn)行:

    kubectl -n foo annotate pod/sample backup.velero.io/backup-volumes=pvc-volume,emptydir-volume
    

    如果您使用控制器來(lái)管理您的 pods,則也可以在 pod template spec 中提供此批注。

  2. 做一個(gè) Velero 備份

    velero backup create NAME OPTIONS...
    
  3. 備份完成后,查看有關(guān)備份的信息:

    velero backup describe YOUR_BACKUP_NAME
    kubectl -n velero get podvolumebackups -l velero.io/backup-name=YOUR_BACKUP_NAME -o yaml
    

恢復(fù)

無(wú)論如何使用 Restic 發(fā)現(xiàn)卷以進(jìn)行備份,還原過(guò)程均保持不變。

  1. 從 Velero 備份中還原:

    velero restore create --from-backup BACKUP_NAME OPTIONS...
    
  2. 還原完成后,查看有關(guān) Pod 卷還原的信息:

    velero restore describe YOUR_RESTORE_NAME
    kubectl -n velero get podvolumerestores -l velero.io/restore-name=YOUR_RESTORE_NAME -o yaml
    

限制

  • 不支持hostPath 卷。 支持 本地持久卷。
  • 熟悉 restic 的人可能知道它會(huì)加密所有數(shù)據(jù)。 Velero 對(duì)它創(chuàng)建的所有 Restic 存儲(chǔ)庫(kù)使用靜態(tài)通用加密密鑰。 這意味著有權(quán)訪問(wèn)您的存儲(chǔ)桶的任何人都可以解密您的還原備份數(shù)據(jù)。 確保適當(dāng)限制對(duì) Restic 桶的訪問(wèn)。
  • 跨 PVC 的 pod 重新安排將維護(hù)增量備份鏈。 但是,對(duì)于非 PVC 的 pod 卷(例如emptyDir 卷),當(dāng)刪除/重新創(chuàng)建 pod(例如,通過(guò) ReplicaSet / Deployment)時(shí),這些卷的下一次備份將是完整的而不是增量的,因?yàn)?pod 卷的是 假定生命周期由其 pod 定義。
  • Restic 在單個(gè)線程中掃描每個(gè)文件。 這意味著大文件(例如存儲(chǔ)數(shù)據(jù)庫(kù)的文件)將花費(fèi)很長(zhǎng)時(shí)間掃描重復(fù)數(shù)據(jù)刪除,即使實(shí)際差異很小。
  • 如果您打算使用 Velero Restic 集成來(lái)備份 100GB 或更多的數(shù)據(jù),則可能需要 自定義資源限制 以確保備份成功完成。
  • Velero 的 Restic 集成通過(guò)訪問(wèn)運(yùn)行 Pod 的節(jié)點(diǎn)文件系統(tǒng)來(lái)備份卷中的數(shù)據(jù)。 因此,RESTIC 集成只能備份由 Pod 掛載的卷,而不能直接從 PVC 備份。

自定義還原助手容器

Velero 在執(zhí)行 Restic 還原時(shí)使用輔助初始化容器。 默認(rèn)情況下,此容器的鏡像是velero/velero-restic-restore-helper:<VERSION> ,其中VERSION 與主 Velero 鏡像的版本/標(biāo)簽匹配。 您可以通過(guò)在 Velero 命名空間中創(chuàng)建帶有備用鏡像的 ConfigMap,來(lái)定制用于此幫助程序的鏡像。

ConfigMap 必須如下所示:

apiVersion: v1
kind: ConfigMap
metadata:
  # any name can be used; Velero uses the labels (below)
  # to identify it rather than the name
  name: restic-restore-action-config
  # must be in the velero namespace
  namespace: velero
  # the below labels should be used verbatim in your
  # ConfigMap.
  labels:
    # this value-less label identifies the ConfigMap as
    # config for a plugin (i.e. the built-in restic restore
    # item action plugin)
    velero.io/plugin-config: ""
    # this label identifies the name and kind of plugin
    # that this ConfigMap is for.
    velero.io/restic: RestoreItemAction
data:
  # The value for "image" can either include a tag or not;
  # if the tag is *not* included, the tag from the main Velero
  # image will automatically be used.
  image: myregistry.io/my-custom-helper-image[:OPTIONAL_TAG]

  # "cpuRequest" sets the request.cpu value on the restic init containers during restore.
  # If not set, it will default to "100m". A value of "0" is treated as unbounded.
  cpuRequest: 200m

  # "memRequest" sets the request.memory value on the restic init containers during restore.
  # If not set, it will default to "128Mi". A value of "0" is treated as unbounded.
  memRequest: 128Mi

  # "cpuLimit" sets the request.cpu value on the restic init containers during restore.
  # If not set, it will default to "100m". A value of "0" is treated as unbounded.
  cpuLimit: 200m

  # "memLimit" sets the request.memory value on the restic init containers during restore.
  # If not set, it will default to "128Mi". A value of "0" is treated as unbounded.
  memLimit: 128Mi

  # "secCtxRunAsUser sets the securityContext.runAsUser value on the restic init containers during restore."
  secCtxRunAsUser: 1001

  # "secCtxRunAsGroup sets the securityContext.runAsGroup value on the restic init containers during restore."
  secCtxRunAsGroup: 999

備份和還原如何與 Restic 一起工作

Velero 具有三個(gè)自定義資源定義和關(guān)聯(lián)的控制器:

  • ResticRepository - 代表/管理 Velero Restic 儲(chǔ)存庫(kù) 的生命周期。 當(dāng)請(qǐng)求第一個(gè)名稱空間的 Restic 備份時(shí),Velero 將為每個(gè)名稱空間創(chuàng)建一個(gè) Restic 存儲(chǔ)庫(kù)。 此自定義資源的控制器執(zhí)行 restic 存儲(chǔ)庫(kù)生命周期命令– restic init,restic checkrestic prune。

    您可以通過(guò)運(yùn)行velero restic repo get 來(lái)查看有關(guān) Velero Restic 存儲(chǔ)庫(kù)的信息。

  • PodVolumeBackup - 表示容器中卷的靜態(tài)備份。當(dāng)找到帶注釋的 pod 時(shí),主要的 Velero 備份過(guò)程會(huì)創(chuàng)建一個(gè)或多個(gè)PodVolumeBackup 。群集中的每個(gè)節(jié)點(diǎn)都為此資源(在 daemonset 中)運(yùn)行一個(gè)控制器,該控制器處理該節(jié)點(diǎn)上的 Pod 的PodVolumeBackups 。 控制器執(zhí)行restic backup命令以備份 pod 卷數(shù)據(jù)。

  • PodVolumeRestore - 表示 pod volume 的恢復(fù)。 當(dāng)遇到具有關(guān)聯(lián)的 Restic 備份的 Pod 時(shí),主要的 Velero 還原過(guò)程會(huì)創(chuàng)建其中的一個(gè)或多個(gè)PodVolumeRestore。 群集中的每個(gè)節(jié)點(diǎn)都為此資源運(yùn)行一個(gè)控制器(在與上述相同的 daemonset 中),該控制器處理該節(jié)點(diǎn)上的 Pod 的PodVolumeRestores。 控制器執(zhí)行restic restore命令以還原 Pod 卷數(shù)據(jù)。

備份

  1. 根據(jù)配置,主要的 Velero 備份過(guò)程使用選擇加入或選擇退出方法來(lái)檢查要備份的每個(gè) Pod,以使用 Restic 備份要備份的卷。
  2. 找到后,Velero 首先通過(guò)以下方式確保 pod 的名稱空間存在一個(gè) Restic 存儲(chǔ)庫(kù):
    • 檢查ResticRepository 自定義資源是否已經(jīng)存在
    • 如果沒(méi)有,創(chuàng)建一個(gè)新的,然后等待ResticRepository 控制器進(jìn)行初始化/檢查。
  3. 然后 Velero 為 pod 注釋中列出的每個(gè)卷創(chuàng)建一個(gè)PodVolumeBackup 自定義資源。
  4. 現(xiàn)在,主要的 Velero 進(jìn)程等待PodVolumeBackup資源完成或失敗
  5. 同時(shí),每個(gè)PodVolumeBackup 由相應(yīng)節(jié)點(diǎn)上的控制器處理:
    • 具有/var/lib/kubelet/pods的 hostPath 卷掛載以訪問(wèn) Pod 卷數(shù)據(jù)
    • 在上述卷中找到 pod 卷的子目錄
    • 運(yùn)行restic backup
    • 將自定義資源的狀態(tài)更新為“Completed”或“Failed”
  6. 每個(gè)PodVolumeBackup 完成時(shí),主 Velero 進(jìn)程會(huì)將其添加到名為<backup-name>-podvolumebackups.json.gz 的文件中的 Velero 備份中。 該文件與備份 tarball 一起上傳到對(duì)象存儲(chǔ)。 它將用于還原,如下一節(jié)所述。

還原

  1. Velero 的主要還原過(guò)程將檢查集群中每個(gè)要備份的現(xiàn)有PodVolumeBackup 自定義資源。

  2. 對(duì)于找到的每個(gè)PodVolumeBackup ,Velero 首先通過(guò)以下方法確保該 pod 的命名空間存在一個(gè) Restic 存儲(chǔ)庫(kù):

    • 檢查ResticRepository 自定義資源是否已經(jīng)存在
    • 如果不存在,則創(chuàng)建一個(gè)新倉(cāng)庫(kù),然后等待ResticRepository 控制器初始化/檢查它(請(qǐng)注意,在這種情況下,實(shí)際的倉(cāng)庫(kù)應(yīng)該已經(jīng)存在于對(duì)象存儲(chǔ)中,因此 Velero 控制器將只對(duì)其進(jìn)行完整性檢查)
  3. Velero 將一個(gè)初始化容器添加到了 pod 中,該容器的工作是等待所有還原恢復(fù)以完成容器(稍后會(huì)詳細(xì)介紹)

  4. Velero 通過(guò)將其提交到 Kubernetes API 來(lái)創(chuàng)建具有添加的 init container 的 pod

  5. Velero 為要在被還原的每個(gè) Pod 中創(chuàng)建PodVolumeRestore 自定義資源

  6. 現(xiàn)在,主要的 Velero 進(jìn)程等待每個(gè)PodVolumeRestore 資源完成或失敗

  7. 同時(shí),每個(gè)PodVolumeRestore 由相應(yīng)節(jié)點(diǎn)上的控制器處理:

    • 具有/var/lib/kubelet/pods的 hostPath 卷掛載以訪問(wèn) Pod 卷數(shù)據(jù)

    • 等待 pod 運(yùn)行 init 容器

    • 在上述卷中找到 pod 卷的子目錄

    • 運(yùn)行restic restore

    • 成功后,將文件寫(xiě)入 Pod 卷中的.velero子目錄中,該文件的名稱是此 Pod 卷還原用于的 Velero 還原的 UID。

    • 將自定義資源的狀態(tài)更新為“Completed”或“Failed”

  8. 添加到 Pod 的 init 容器正在運(yùn)行一個(gè)過(guò)程,該過(guò)程一直等到它在每個(gè)已還原卷中的.velero 下找到一個(gè)文件,其名稱是正在運(yùn)行的 Velero 還原的 UID

  9. 找到所有此類文件后,初始化容器的過(guò)程將成功終止,并且 pod 將繼續(xù)運(yùn)行其他初始化容器/主容器。

第三方控制器

監(jiān)控備份注釋

Velero 沒(méi)有提供一種機(jī)制來(lái)檢測(cè)缺少 restic 備份注釋的持久卷聲明。

為了解決這個(gè)問(wèn)題,Thomann Bits&Beats 編寫(xiě)了一個(gè)控制器:velero-pvc-watcher

使用 - 集群遷移

使用 BackupsRestores

只要您將每個(gè) Velero 實(shí)例指向相同的云對(duì)象存儲(chǔ)位置,Velero 就能幫助您將資源從一個(gè)群集移植到另一個(gè)群集。 此方案假定您的群集由同一云提供商托管。 請(qǐng)注意,Velero 本身不支持跨云提供程序遷移持久卷快照。 如果要在云平臺(tái)之間遷移卷數(shù)據(jù),請(qǐng)啟用 restic,它將在文件系統(tǒng)級(jí)別備份卷內(nèi)容。

  1. (集群 1)假設(shè)您尚未使用 Velero schedule 操作對(duì)數(shù)據(jù)進(jìn)行檢查點(diǎn)檢查,則需要首先備份整個(gè)群集(根據(jù)需要替換<BACKUP-NAME>):

    velero backup create <BACKUP-NAME>
    

    默認(rèn)備份保留期限以 TTL(有效期)表示,為 30 天(720 小時(shí)); 您可以使用--ttl <DURATION>標(biāo)志根據(jù)需要進(jìn)行更改。 有關(guān)備份到期的更多信息,請(qǐng)參見(jiàn) velero 的工作原理

  2. (集群 2)配置BackupStorageLocationsVolumeSnapshotLocations, 指向 集群 1 使用的位置,使用velero backup-location createvelero snapshot-location create. 確保配置BackupStorageLocations為 read-only 通過(guò)在velero backup-location create時(shí)使用--access-mode=ReadOnly flag

  3. (集群 2)確保已創(chuàng)建 Velero Backup 對(duì)象。 Velero 資源與云存儲(chǔ)中的備份文件同步。

    velero backup describe <BACKUP-NAME>
    

    注意:默認(rèn)同步間隔為 1 分鐘,因此請(qǐng)確保在檢查之前等待。 您可以使用 Velero 服務(wù)器的--backup-sync-period標(biāo)志配置此間隔。

  4. (集群 2)一旦確認(rèn)現(xiàn)在存在正確的備份(<BACKUP-NAME>),就可以使用以下方法還原所有內(nèi)容:

    velero restore create --from-backup <BACKUP-NAME>
    

驗(yàn)證 2 個(gè)集群

檢查第二個(gè)群集是否按預(yù)期運(yùn)行:

  1. (集群 2) 運(yùn)行:

    velero restore get
    
  2. 然后運(yùn)行:

    velero restore describe <RESTORE-NAME-FROM-GET-COMMAND>
    

如果遇到問(wèn)題,請(qǐng)確保 Velero 在兩個(gè)群集中的相同 namespace 中運(yùn)行。

使用 - 資源過(guò)濾

按 namespace、類型或標(biāo)簽篩選對(duì)象。

當(dāng)不使用任何篩選選項(xiàng)時(shí),Velero 會(huì)將所有對(duì)象包括在備份或還原中。

Includes

僅包括特定資源,不包括所有其他資源。

如果同時(shí)包含通配符和特定資源,則通配符優(yōu)先。

–include-namespaces

  • 備份 namespace 及其對(duì)象。

    velero backup create <backup-name> --include-namespaces <namespace>
    
  • 恢復(fù)兩個(gè) namespace 及其對(duì)象。

    velero restore create <backup-name> --include-namespaces <namespace1>,<namespace2>
    

–include-resources

  • 備份集群中的所有 deployments:

    velero backup create <backup-name> --include-resources deployments
    
  • 恢復(fù)集群中的所有 deployments 和 configmaps。

    velero restore create <backup-name> --include-resources deployments,configmaps
    
  • 在 namespace 中備份 deployments。

    velero backup create <backup-name> --include-resources deployments --include-namespaces <namespace>
    

–include-cluster-resources

此選項(xiàng)可以具有三個(gè)可能的值:

  • true: 包括所有群集范圍的資源。

  • false: 不包括群集范圍的資源。

  • nil("auto"或不提供):

    • 備份或還原所有 namespace 時(shí),將包括群集范圍的資源。 默認(rèn)值:true
    • 使用 namespace 過(guò)濾時(shí),不包括群集范圍的資源。 默認(rèn)值:false
      • 除非--include-cluster-resources = false,否則如果由自定義操作(例如,PVC-> PV)觸發(fā)某些相關(guān)的群集作用域資源,則可能仍會(huì)進(jìn)行備份/還原。
  • 備份整個(gè)群集,包括群集范圍內(nèi)的資源。

    velero backup create <backup-name>
    
  • 僅還原群集中的命名空間資源。

    velero restore create <backup-name> --include-cluster-resources=false
    
  • 備份 namespace 并包括群集范圍的資源。

    velero backup create <backup-name> --include-namespaces <namespace> --include-cluster-resources=true 
    

–selector

包括與 label selector 匹配的資源。

velero backup create <backup-name> --selector <key>=<value>

Excludes

從備份中排除特定資源。

通配符排除將被忽略。

–exclude-namespaces

  • Exclude kube-system from the cluster backup.

    velero backup create <backup-name> --exclude-namespaces kube-system
    
  • 還原期間排除兩個(gè) namespace。

    velero restore create <backup-name> --exclude-namespaces <namespace1>,<namespace2>
    

–exclude-resources

  • 從備份中排除 secrets:

    velero backup create <backup-name> --exclude-resources secrets
    
  • 排除 secrets 和 rolebindings:

    velero backup create <backup-name> --exclude-resources secrets,rolebindings
    

velero.io/exclude-from-backup=true

標(biāo)簽為velero.io/exclude-from-backup=true的資源不包括在備份中,即使它包含匹配的選擇器標(biāo)簽也是如此。

系列文章

???參考文檔

三人行, 必有我?guī)? 知識(shí)共享, 天下為公. 本文由東風(fēng)微鳴技術(shù)博客 EWhisper.cn 編寫(xiě).

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容