概述
Velero 是一個開源工具,可以安全地備份和還原点寥,執(zhí)行災難恢復以及遷移 Kubernetes 集群資源和持久卷囚枪。
災難恢復
Velero 可以在基礎(chǔ)架構(gòu)丟失,數(shù)據(jù)損壞和/或服務(wù)中斷的情況下盟萨,減少恢復時間。
數(shù)據(jù)遷移
Velero 通過輕松地將 Kubernetes 資源從一個集群遷移到另一個集群來實現(xiàn)集群可移植性
數(shù)據(jù)保護
提供關(guān)鍵數(shù)據(jù)保護功能了讨,例如定時計劃的備份捻激,保留計劃以及自定義操作的備份前或備份后鉤子。
備份集群
使用 namespace resources 或 label selector 備份整個集群或部分集群的 Kubernetes 資源和卷前计。
定期備份
設(shè)置計劃以定期間隔自動啟動備份胞谭。
備份鉤子
配置備份前和備份后鉤子,以在 Velero 備份之前和之后執(zhí)行自定義操作残炮。
安裝 - 基本安裝
前提
- 在啟用 DNS 和容器聯(lián)網(wǎng)的情況下訪問 Kubernetes 集群 v1.16 或更高版本韭赘。
-
kubectl
本地安裝
Velero 使用對象存儲來存儲備份和關(guān)聯(lián)的工件。 它還可以選擇與受支持的塊存儲系統(tǒng)集成势就,以對您的持久卷進行快照泉瞻。 在開始安裝過程之前,您應(yīng)該從 兼容的提供程序列表 中識別將要使用的對象存儲提供程序和可選的塊存儲提供程序苞冯。
Velero 支持云提供商環(huán)境和本地環(huán)境的存儲提供商袖牙。 有關(guān)內(nèi)部部署方案的更多詳細信息,請參見 內(nèi)部部署文檔
安裝 CLI
- 下載適用于您的客戶端平臺的 最新版本 的 tarball舅锄。
- 解壓 tarball:
tar -xvf <RELEASE-TARBALL-NAME>.tar.gz
- 將解壓后的
velero
放到$PATH
(一般是/usr/local/bin
)
安裝配置 server 端組件
有兩種支持的方法來安裝 Velero 服務(wù)器組件:
-
velero install
CLI 命令 - Helm Chart
Velero 使用存儲提供程序插件與各種存儲系統(tǒng)集成鞭达,以支持備份和快照操作。 安裝和配置 Velero 服務(wù)器組件以及相應(yīng)插件的步驟特定于您選擇的存儲提供商。 要查找您選擇的存儲提供商的安裝說明畴蹭,請在 支持的存儲提供商 頁面上訪問提供商的文檔鏈接坦仍。
?? 注意:
如果您的對象存儲提供程序與卷快照提供程序不同,請首先按照對象存儲提供程序的安裝說明進行操作叨襟,然后返回此處并按照說明添加 卷快照提供程序繁扎。
命令行自動補全
https://velero.io/docs/v1.8/customize-installation/#enabling-shell-autocompletion
安裝 - 定制化安裝
https://velero.io/docs/v1.8/customize-installation/
安裝 - 提供商
Velero 支持各種存儲提供程序,以進行不同的備份和快照操作糊闽。 Velero 有一個插件系統(tǒng)梳玫,它允許任何人在不修改 Velero 代碼庫的情況下增加對其他備份和卷存儲平臺的兼容性。
Velero 支持的提供商
提供商 | 對象存儲 | 卷快照 | 插件提供商 Repo | 安裝說明 |
---|---|---|---|---|
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 兼容的對象存儲提供程序
Velero 的 AWS Object Store 插件使用 Amazon 的 Go SDK 連接到 AWS S3 API右犹。 一些第三方存儲提供程序也支持 S3 API提澎,并且用戶報告了以下提供程序可用于 Velero:
?? 請注意,Velero 團隊并未定期測試這些存儲提供商念链。
- IBM Cloud
- Oracle Cloud
- Minio
- DigitalOcean
- NooBaa
- Tencent Cloud
- Ceph RADOS v12.2.7
- Quobyte
- Cloudian HyperStore
某些存儲提供程序(例如 Quobyte)可能需要不同的簽名算法版本盼忌。
安裝 - 快速驗證安裝
-
在您的本地目錄中創(chuàng)建特定于 Velero 的憑證文件(
credentials-velero
):[default] aws_access_key_id = minio aws_secret_access_key = minio123
-
啟動服務(wù)器和存儲服務(wù)。 在 Velero 目錄中钓账,運行:
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
此示例假定它在本地群集中運行碴犬,而沒有能夠提供快照的卷提供程序,因此不會創(chuàng)建 VolumeSnapshotLocation(``--use-volume-snapshots=false`)梆暮。
此外,您可以指定
--use-restic
啟用 RESTIC 支持绍昂,并指定--wait
等待部署準備就緒啦粹。對于更復雜的安裝需求,請使用 Helm Chart窘游,或添加
--dry-run -o yaml
選項來生成安裝的 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.
備份
-
為與
app=iperf3-server
label selector 匹配的任何對象創(chuàng)建備份:velero backup create test-backup --selector app=iperf3-server
或者,如果要備份除匹配標簽
backup=ignore
的對象以外的所有對象忍饰,請執(zhí)行以下操作:velero backup create nginx-backup --selector 'backup!=ignore'
-
(可選)使用
app=iperf3-server
label selector 基于 cron 表達式創(chuàng)建定期計劃的備份:velero schedule create test-daily --schedule="0 1 * * *" --selector app=iperf3-server
另外贪嫂,您可以使用一些非標準的速記 cron 表達式:
velero schedule create test-daily --schedule="@every 24h" --selector app=iperf3-server
有關(guān)更多用法示例,請參見 cron 軟件包 的文檔艾蓝。
恢復
-
運行:
velero restore create --from-backup test-backup
-
運行:
velero restore get
恢復完成后力崇,輸出如下所示:
NAME BACKUP STATUS WARNINGS ERRORS CREATED SELECTOR nginx-backup-20170727200524 nginx-backup Completed 0 0 2017-07-27 20:05:24 +0000 UTC <none>
如果有錯誤或警告,則可以詳細查看它們:
velero restore describe <RESTORE_NAME>
清理
如果要刪除創(chuàng)建的所有備份赢织,包括對象存儲中的數(shù)據(jù)和永久卷快照亮靴,則可以運行:
velero backup delete BACKUP_NAME
這要求 Velero 服務(wù)器刪除與BACKUP_NAME
相關(guān)聯(lián)的所有備份數(shù)據(jù)。 您需要對要永久刪除的每個備份執(zhí)行此操作于置。 Velero 的未來版本將允許您通過名稱或 label selector 刪除多個備份茧吊。
要從 Kubernetes 集群中完全卸載 Velero:
oc delete namespace/velero clusterrolebinding/velero
oc delete crds -l component=velero
安裝 - Restic 集成
Velero 支持使用稱為 restic 的免費開源備份工具備份和還原 Kubernetes 卷。 此支持被視為 Beta 質(zhì)量。 請查看 限制 列表搓侄,以了解它是否適合您的用例瞄桨。
添加了 Restic 集成,為您提供了一個現(xiàn)成的解決方案讶踪,用于備份和還原幾乎任何類型的 Kubernetes 卷芯侥。 這種集成是 Velero 功能的補充,而不是現(xiàn)有功能的替代俊柔。 但是筹麸,如果您需要為存儲平臺使用卷快照插件,或者使用的是 EFS雏婶,AzureFile物赶,NFS,emptyDir留晚,local 或任何其他沒有本機快照概念的卷類型酵紫,restic 可能適合您 。
Restic 并不局限于特定的存儲平臺错维,這意味著該集成還為將來實現(xiàn)跨卷類型數(shù)據(jù)遷移的工作鋪平了道路奖地。
?? 注意:
不支持 hostPath 卷,但是支持 本地卷類型赋焕。
安裝 restic
前提
了解 Velero 如何 通過 Restic 集成執(zhí)行備份参歹。
下載 最新的 Velero 版本。
Kubernetes v1.10.0 及更高版本隆判。 Velero 的 Restic 集成需要 Kubernetes MountPropagation 功能犬庇,該功能在 Kubernetes v1.10.0 和更高版本中默認啟用。
安裝 restic
要安裝 restic侨嘀,請使用velero install
命令中的--use-restic
標志臭挽。 有關(guān)安裝命令的其他標志的更多詳細信息,請參見 安裝概述咬腕。
velero install --use-restic
在不支持快照的 Velero 支持的存儲提供程序上使用 Restic 時欢峰,--use-volume-snapshots = false
標志可防止在安裝時創(chuàng)建未使用的VolumeSnapshotLocation
。
配置 Restic DaemonSet Spec
安裝后涨共,某些基于 Kubernetes 的 PaaS / CaaS 平臺也需要修改 Restic DaemonSet 規(guī)范纽帖。 僅當您在 RancherOS,OpenShift煞赢,VMware Tanzu Kubernetes Grid Integrated Edition(以前稱為 VMware Enterprise PKS)或 Micrsoft Azure 上安裝時抛计,才需要本節(jié)中的步驟。
OpenShift
要將正確的主機路徑安裝到 Pod 卷照筑,請在privileged
模式下運行 Restic Pod吹截。
-
將
velero
ServiceAccount 添加到privileged
SCC:$ oc adm policy add-scc-to-user privileged -z velero -n velero
-
對于 OpenShift 版本> = 4.1瘦陈,修改 DaemonSet yaml 以請求
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)模式下運行,則由于主機系統(tǒng)級別配置了默認的強制實施 SELinux 模式波俄,它將無法訪問已掛載的 hostpath 目錄內(nèi)的 pod 卷晨逝。 您可以 創(chuàng)建自定義 SCC 來放松群集中的安全性,以便允許 Restic Pod 使用 hostPath 卷插件懦铺,而無需授予它們訪問privileged
SCC 的權(quán)限捉貌。
默認情況下,用戶維度的 openshift 名稱空間不會在集群中的所有節(jié)點上調(diào)度 Pod冬念。
要在所有節(jié)點上計劃名稱空間趁窃,需要一個注釋:
oc annotate namespace <velero namespace> openshift.io/node-selector=""
這應(yīng)該在安裝 velero 之前完成。
或需要刪除并重新創(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 卷的兩種方法:
選擇性啟用方式:每個包含要使用 Restic 備份的卷的 Pod 都必須標有卷的名稱急前。
選擇性退出方式:使用 Restic 備份所有 Pod 卷醒陆,并具有退出任何不應(yīng)備份的卷的功能。
以下各節(jié)提供了有關(guān)這兩種方法的更多詳細信息裆针。
選擇性退出方式
在這種方法中刨摩,Velero 將使用 restic 備份所有 pod 卷,但以下情況除外:
- 安裝默認服務(wù)帳戶令牌世吨,kubernetes secrets 和 config maps 的卷
- Hostpath 卷
使用 pod 上的backup.velero.io/backup-volumes-excludes
注釋可以排除卷不被備份的情況澡刹。
使用此方法進行備份的說明如下:
-
在包含不應(yīng)使用 Restic 備份的卷的每個 Pod 上運行以下命令
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)運行:kubectl -n sample annotate pod/app1 backup.velero.io/backup-volumes-excludes=pvc1-vm
-
進行 Velero 備份:
velero backup create BACKUP_NAME --default-volumes-to-restic OTHER_OPTIONS
以上步驟在每個備份的基礎(chǔ)上使用了選擇性退出方法沐祷。
或者己莺,可以在運行帶有
--default-volumes-to-restic
標志的velero install
命令的所有 velero 備份上啟用此行為。 有關(guān)詳細信息戈轿,請參閱 安裝概述。 -
備份完成后阵子,查看有關(guān)備份的信息:
velero backup describe YOUR_BACKUP_NAME kubectl -n velero get podvolumebackups -l velero.io/backup-name=YOUR_BACKUP_NAME -o yaml
選擇性啟用方式
默認情況下思杯,Velero 使用這種方法來發(fā)現(xiàn)需要使用 Restic 備份的 Pod 卷,其中每個包含要使用 Restic 備份的卷的 Pod 都必須標有該卷的名稱挠进。
使用此方法進行備份的說明如下:
-
對包含要備份的卷的每個 Pod 運行以下命令:
kubectl -n YOUR_POD_NAMESPACE annotate pod/YOUR_POD_NAME backup.velero.io/backup-volumes=YOUR_VOLUME_NAME_1,YOUR_VOLUME_NAME_2,...
其中色乾,卷名是容器 spec 中卷的名稱。
例如领突,對于以下 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)該運行:
kubectl -n foo annotate pod/sample backup.velero.io/backup-volumes=pvc-volume,emptydir-volume
如果您使用控制器來管理您的 pods暖璧,則也可以在 pod template spec 中提供此批注。
-
做一個 Velero 備份
velero backup create NAME OPTIONS...
-
備份完成后君旦,查看有關(guān)備份的信息:
velero backup describe YOUR_BACKUP_NAME kubectl -n velero get podvolumebackups -l velero.io/backup-name=YOUR_BACKUP_NAME -o yaml
恢復
無論如何使用 Restic 發(fā)現(xiàn)卷以進行備份澎办,還原過程均保持不變嘲碱。
-
從 Velero 備份中還原:
velero restore create --from-backup BACKUP_NAME OPTIONS...
-
還原完成后,查看有關(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 的人可能知道它會加密所有數(shù)據(jù)。 Velero 對它創(chuàng)建的所有 Restic 存儲庫使用靜態(tài)通用加密密鑰琅绅。 這意味著有權(quán)訪問您的存儲桶的任何人都可以解密您的還原備份數(shù)據(jù)扶欣。 確保適當限制對 Restic 桶的訪問。
- 跨 PVC 的 pod 重新安排將維護增量備份鏈千扶。 但是料祠,對于非 PVC 的 pod 卷(例如
emptyDir
卷),當刪除/重新創(chuàng)建 pod(例如澎羞,通過 ReplicaSet / Deployment)時髓绽,這些卷的下一次備份將是完整的而不是增量的,因為 pod 卷的是 假定生命周期由其 pod 定義煤痕。 - Restic 在單個線程中掃描每個文件梧宫。 這意味著大文件(例如存儲數(shù)據(jù)庫的文件)將花費很長時間掃描重復數(shù)據(jù)刪除,即使實際差異很小摆碉。
- 如果您打算使用 Velero Restic 集成來備份 100GB 或更多的數(shù)據(jù)塘匣,則可能需要 自定義資源限制 以確保備份成功完成。
- Velero 的 Restic 集成通過訪問運行 Pod 的節(jié)點文件系統(tǒng)來備份卷中的數(shù)據(jù)巷帝。 因此忌卤,RESTIC 集成只能備份由 Pod 掛載的卷,而不能直接從 PVC 備份楞泼。
自定義還原助手容器
Velero 在執(zhí)行 Restic 還原時使用輔助初始化容器驰徊。 默認情況下,此容器的鏡像是velero/velero-restic-restore-helper:<VERSION>
堕阔,其中VERSION
與主 Velero 鏡像的版本/標簽匹配棍厂。 您可以通過在 Velero 命名空間中創(chuàng)建帶有備用鏡像的 ConfigMap,來定制用于此幫助程序的鏡像超陆。
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 具有三個自定義資源定義和關(guān)聯(lián)的控制器:
-
ResticRepository
- 代表/管理 Velero Restic 儲存庫 的生命周期牺弹。 當請求第一個名稱空間的 Restic 備份時,Velero 將為每個名稱空間創(chuàng)建一個 Restic 存儲庫时呀。 此自定義資源的控制器執(zhí)行 restic 存儲庫生命周期命令–restic init
张漂,restic check
和restic prune
。您可以通過運行
velero restic repo get
來查看有關(guān) Velero Restic 存儲庫的信息谨娜。 PodVolumeBackup
- 表示容器中卷的靜態(tài)備份航攒。當找到帶注釋的 pod 時,主要的 Velero 備份過程會創(chuàng)建一個或多個PodVolumeBackup
趴梢。群集中的每個節(jié)點都為此資源(在 daemonset 中)運行一個控制器漠畜,該控制器處理該節(jié)點上的 Pod 的PodVolumeBackups
币他。 控制器執(zhí)行restic backup
命令以備份 pod 卷數(shù)據(jù)。PodVolumeRestore
- 表示 pod volume 的恢復盆驹。 當遇到具有關(guān)聯(lián)的 Restic 備份的 Pod 時圆丹,主要的 Velero 還原過程會創(chuàng)建其中的一個或多個PodVolumeRestore
。 群集中的每個節(jié)點都為此資源運行一個控制器(在與上述相同的 daemonset 中)躯喇,該控制器處理該節(jié)點上的 Pod 的PodVolumeRestores
辫封。 控制器執(zhí)行restic restore
命令以還原 Pod 卷數(shù)據(jù)。
備份
- 根據(jù)配置廉丽,主要的 Velero 備份過程使用選擇加入或選擇退出方法來檢查要備份的每個 Pod倦微,以使用 Restic 備份要備份的卷。
- 找到后正压,Velero 首先通過以下方式確保 pod 的名稱空間存在一個 Restic 存儲庫:
- 檢查
ResticRepository
自定義資源是否已經(jīng)存在 - 如果沒有欣福,創(chuàng)建一個新的,然后等待
ResticRepository
控制器進行初始化/檢查焦履。
- 檢查
- 然后 Velero 為 pod 注釋中列出的每個卷創(chuàng)建一個
PodVolumeBackup
自定義資源拓劝。 - 現(xiàn)在,主要的 Velero 進程等待
PodVolumeBackup
資源完成或失敗 - 同時嘉裤,每個
PodVolumeBackup
由相應(yīng)節(jié)點上的控制器處理:- 具有
/var/lib/kubelet/pods
的 hostPath 卷掛載以訪問 Pod 卷數(shù)據(jù) - 在上述卷中找到 pod 卷的子目錄
- 運行
restic backup
- 將自定義資源的狀態(tài)更新為“Completed”或“Failed”
- 具有
- 每個
PodVolumeBackup
完成時郑临,主 Velero 進程會將其添加到名為<backup-name>-podvolumebackups.json.gz
的文件中的 Velero 備份中。 該文件與備份 tarball 一起上傳到對象存儲屑宠。 它將用于還原厢洞,如下一節(jié)所述。
還原
Velero 的主要還原過程將檢查集群中每個要備份的現(xiàn)有
PodVolumeBackup
自定義資源典奉。-
對于找到的每個
PodVolumeBackup
躺翻,Velero 首先通過以下方法確保該 pod 的命名空間存在一個 Restic 存儲庫:- 檢查
ResticRepository
自定義資源是否已經(jīng)存在 - 如果不存在,則創(chuàng)建一個新倉庫卫玖,然后等待
ResticRepository
控制器初始化/檢查它(請注意公你,在這種情況下,實際的倉庫應(yīng)該已經(jīng)存在于對象存儲中假瞬,因此 Velero 控制器將只對其進行完整性檢查)
- 檢查
Velero 將一個初始化容器添加到了 pod 中省店,該容器的工作是等待所有還原恢復以完成容器(稍后會詳細介紹)
Velero 通過將其提交到 Kubernetes API 來創(chuàng)建具有添加的 init container 的 pod
Velero 為要在被還原的每個 Pod 中創(chuàng)建
PodVolumeRestore
自定義資源現(xiàn)在,主要的 Velero 進程等待每個
PodVolumeRestore
資源完成或失敗-
同時笨触,每個
PodVolumeRestore
由相應(yīng)節(jié)點上的控制器處理:具有
/var/lib/kubelet/pods
的 hostPath 卷掛載以訪問 Pod 卷數(shù)據(jù)等待 pod 運行 init 容器
在上述卷中找到 pod 卷的子目錄
運行
restic restore
成功后,將文件寫入 Pod 卷中的
.velero
子目錄中雹舀,該文件的名稱是此 Pod 卷還原用于的 Velero 還原的 UID芦劣。將自定義資源的狀態(tài)更新為“Completed”或“Failed”
添加到 Pod 的 init 容器正在運行一個過程,該過程一直等到它在每個已還原卷中的
.velero
下找到一個文件说榆,其名稱是正在運行的 Velero 還原的 UID找到所有此類文件后虚吟,初始化容器的過程將成功終止寸认,并且 pod 將繼續(xù)運行其他初始化容器/主容器。
第三方控制器
監(jiān)控備份注釋
Velero 沒有提供一種機制來檢測缺少 restic 備份注釋的持久卷聲明串慰。
為了解決這個問題偏塞,Thomann Bits&Beats 編寫了一個控制器:velero-pvc-watcher
使用 - 集群遷移
使用 Backups 和 Restores
只要您將每個 Velero 實例指向相同的云對象存儲位置,Velero 就能幫助您將資源從一個群集移植到另一個群集邦鲫。 此方案假定您的群集由同一云提供商托管灸叼。 請注意,Velero 本身不支持跨云提供程序遷移持久卷快照庆捺。 如果要在云平臺之間遷移卷數(shù)據(jù)古今,請啟用 restic,它將在文件系統(tǒng)級別備份卷內(nèi)容滔以。
-
(集群 1)假設(shè)您尚未使用 Velero
schedule
操作對數(shù)據(jù)進行檢查點檢查捉腥,則需要首先備份整個群集(根據(jù)需要替換<BACKUP-NAME>
):velero backup create <BACKUP-NAME>
默認備份保留期限以 TTL(有效期)表示,為 30 天(720 小時)你画; 您可以使用
--ttl <DURATION>
標志根據(jù)需要進行更改抵碟。 有關(guān)備份到期的更多信息,請參見 velero 的工作原理坏匪。 (集群 2)配置
BackupStorageLocations
和VolumeSnapshotLocations
, 指向 集群 1 使用的位置拟逮,使用velero backup-location create
和velero snapshot-location create
. 確保配置BackupStorageLocations
為 read-only 通過在velero backup-location create
時使用--access-mode=ReadOnly
flag-
(集群 2)確保已創(chuàng)建 Velero Backup 對象。 Velero 資源與云存儲中的備份文件同步剥槐。
velero backup describe <BACKUP-NAME>
注意:默認同步間隔為 1 分鐘唱歧,因此請確保在檢查之前等待。 您可以使用 Velero 服務(wù)器的
--backup-sync-period
標志配置此間隔粒竖。 -
(集群 2)一旦確認現(xiàn)在存在正確的備份(
<BACKUP-NAME>
)颅崩,就可以使用以下方法還原所有內(nèi)容:velero restore create --from-backup <BACKUP-NAME>
驗證 2 個集群
檢查第二個群集是否按預期運行:
-
(集群 2) 運行:
velero restore get
-
然后運行:
velero restore describe <RESTORE-NAME-FROM-GET-COMMAND>
如果遇到問題,請確保 Velero 在兩個群集中的相同 namespace 中運行蕊苗。
使用 - 資源過濾
按 namespace沿后、類型或標簽篩選對象。
當不使用任何篩選選項時朽砰,Velero 會將所有對象包括在備份或還原中尖滚。
Includes
僅包括特定資源,不包括所有其他資源瞧柔。
如果同時包含通配符和特定資源漆弄,則通配符優(yōu)先。
–include-namespaces
-
備份 namespace 及其對象造锅。
velero backup create <backup-name> --include-namespaces <namespace>
-
恢復兩個 namespace 及其對象撼唾。
velero restore create <backup-name> --include-namespaces <namespace1>,<namespace2>
–include-resources
-
備份集群中的所有 deployments:
velero backup create <backup-name> --include-resources deployments
-
恢復集群中的所有 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
此選項可以具有三個可能的值:
true
: 包括所有群集范圍的資源倒谷。false
: 不包括群集范圍的資源蛛蒙。-
nil
("auto"或不提供):- 備份或還原所有 namespace 時,將包括群集范圍的資源渤愁。 默認值:
true
牵祟。 - 使用 namespace 過濾時,不包括群集范圍的資源抖格。 默認值:
false
- 除非
--include-cluster-resources = false
诺苹,否則如果由自定義操作(例如,PVC-> PV)觸發(fā)某些相關(guān)的群集作用域資源他挎,則可能仍會進行備份/還原筝尾。
- 除非
- 備份或還原所有 namespace 時,將包括群集范圍的資源渤愁。 默認值:
-
備份整個群集,包括群集范圍內(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
-
還原期間排除兩個 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
標簽為velero.io/exclude-from-backup=true
的資源不包括在備份中摧阅,即使它包含匹配的選擇器標簽也是如此。
系列文章
???參考文檔
三人行, 必有我?guī)? 知識共享, 天下為公. 本文由東風微鳴技術(shù)博客 EWhisper.cn 編寫.