$ oc --kubeconfig <management_cluster_kubeconfig_file> \
patch hostedcluster -n <hosted_cluster_namespace> <hosted_cluster_name> \
--type json -p '[{"op": "add", "path": "/spec/pausedUntil", "value": "true"}]'
您可以使用 OpenShift API for Data Protection (OADP) 运算符对 Amazon Web Services (AWS) 和裸机执行灾难恢复。
使用 OpenShift API for Data Protection (OADP) 的灾难恢复过程包括以下步骤
准备您的平台,例如 Amazon Web Services 或裸机,以使用 OADP
备份数据平面工作负载
备份控制平面工作负载
使用 OADP 恢复托管集群
您必须在管理集群上满足以下先决条件
您已安装 OADP 运算符。
您已创建存储类。
您可以使用 `cluster-admin` 权限访问集群。
您可以通过目录源访问 OADP 订阅。
您可以访问与 OADP 兼容的云存储提供商,例如 S3、Microsoft Azure、Google Cloud Platform 或 MinIO。
在断开连接的环境中,您可以访问自托管存储提供商,例如Red Hat OpenShift Data Foundation或MinIO,它与 OADP 兼容。
您的托管控制平面 Pod 正在运行。
要对托管集群执行灾难恢复,您可以在 Amazon Web Services (AWS) S3 兼容存储上使用 OpenShift API for Data Protection (OADP)。创建 `DataProtectionApplication` 对象后,将在 `openshift-adp` 命名空间中创建新的 `velero` 部署和 `node-agent` Pod。
要准备使用 OADP 的 AWS,请参阅“使用多云对象网关配置 OpenShift API for Data Protection”。
备份数据平面工作负载
备份控制平面工作负载
要对托管集群执行灾难恢复,您可以在裸机上使用 OpenShift API for Data Protection (OADP)。创建 `DataProtectionApplication` 对象后,将在 `openshift-adp` 命名空间中创建新的 `velero` 部署和 `node-agent` Pod。
要准备使用 OADP 的裸机,请参阅“使用 AWS S3 兼容存储配置 OpenShift API for Data Protection”。
备份数据平面工作负载
备份控制平面工作负载
您可以通过创建 `Backup` 自定义资源 (CR) 来备份控制平面工作负载。
要监控和观察备份过程,请参阅“观察备份和恢复过程”。
通过运行以下命令暂停 `HostedCluster` 资源的协调
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
patch hostedcluster -n <hosted_cluster_namespace> <hosted_cluster_name> \
--type json -p '[{"op": "add", "path": "/spec/pausedUntil", "value": "true"}]'
通过运行以下命令获取托管集群的基础设施 ID
$ oc get hostedcluster -n local-cluster <hosted_cluster_name> -o=jsonpath="{.spec.infraID}"
记下下一步中要使用的基础设施 ID。
通过运行以下命令暂停 `cluster.cluster.x-k8s.io` 资源的协调
$ oc patch cluster.cluster.x-k8s.io \
-n local-cluster-<hosted_cluster_name> <hosted_cluster_infra_id> \
--type json -p '[{"op": "add", "path": "/spec/paused", "value": true}]'
运行以下命令暂停NodePool
资源的协调:
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
patch nodepool -n <hosted_cluster_namespace> <node_pool_name> \
--type json -p '[{"op": "add", "path": "/spec/pausedUntil", "value": "true"}]'
运行以下命令暂停AgentCluster
资源的协调:
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
annotate agentcluster -n <hosted_control_plane_namespace> \
cluster.x-k8s.io/paused=true --all'
运行以下命令暂停AgentMachine
资源的协调:
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
annotate agentmachine -n <hosted_control_plane_namespace> \
cluster.x-k8s.io/paused=true --all'
运行以下命令为HostedCluster
资源添加注释,以防止删除托管控制平面命名空间:
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
annotate hostedcluster -n <hosted_cluster_namespace> <hosted_cluster_name> \
hypershift.openshift.io/skip-delete-hosted-controlplane-namespace=true
创建一个定义Backup
CR 的YAML文件。
backup-control-plane.yaml
文件示例:apiVersion: velero.io/v1
kind: Backup
metadata:
name: <backup_resource_name> (1)
namespace: openshift-adp
labels:
velero.io/storage-location: default
spec:
hooks: {}
includedNamespaces: (2)
- <hosted_cluster_namespace> (3)
- <hosted_control_plane_namespace> (4)
includedResources:
- sa
- role
- rolebinding
- pod
- pvc
- pv
- bmh
- configmap
- infraenv (5)
- priorityclasses
- pdb
- agents
- hostedcluster
- nodepool
- secrets
- hostedcontrolplane
- cluster
- agentcluster
- agentmachinetemplate
- agentmachine
- machinedeployment
- machineset
- machine
excludedResources: []
storageLocation: default
ttl: 2h0m0s
snapshotMoveData: true (6)
datamover: "velero" (6)
defaultVolumesToFsBackup: true (7)
1 | 将backup_resource_name 替换为您的Backup 资源的名称。 |
2 | 选择特定命名空间来备份其中的对象。您必须包含您的托管集群命名空间和托管控制平面命名空间。 |
3 | 将<hosted_cluster_namespace> 替换为托管集群命名空间的名称,例如clusters 。 |
4 | 将<hosted_control_plane_namespace> 替换为托管控制平面命名空间的名称,例如clusters-hosted 。 |
5 | 您必须在单独的命名空间中创建infraenv 资源。在备份过程中不要删除infraenv 资源。 |
6 | 启用CSI卷快照并自动将控制平面工作负载上传到云存储。 |
7 | 将fs-backup 备份方法设置为持久卷 (PV) 的默认方法。当您同时使用容器存储接口 (CSI) 卷快照和fs-backup 方法时,此设置非常有用。 |
如果您想使用CSI卷快照,则必须将 |
运行以下命令应用Backup
CR:
$ oc apply -f backup-control-plane.yaml
运行以下命令验证status.phase
的值是否为Completed
:
$ oc get backups.velero.io <backup_resource_name> -n openshift-adp -o jsonpath='{.status.phase}'
使用 OADP 恢复托管集群
您可以通过创建Restore
自定义资源 (CR) 来恢复托管集群。
如果您使用的是就地更新,则InfraEnv不需要备用节点。您需要从新的管理集群重新配置工作节点。
如果您使用的是替换更新,则InfraEnv需要一些备用节点来部署工作节点。
备份托管集群后,您必须将其销毁以启动恢复过程。要启动节点配置,您必须在删除托管集群之前备份数据平面中的工作负载。 |
您已完成使用控制台删除集群中的步骤以删除您的托管集群。
您已完成删除集群后删除剩余资源中的步骤。
要监控和观察备份过程,请参阅“观察备份和恢复过程”。
运行以下命令验证托管控制平面命名空间中是否存在 Pod 和持久卷声明 (PVC):
$ oc get pod pvc -n <hosted_control_plane_namespace>
No resources found
创建一个定义Restore
CR 的YAML文件。
restore-hosted-cluster.yaml
文件示例:apiVersion: velero.io/v1
kind: Restore
metadata:
name: <restore_resource_name> (1)
namespace: openshift-adp
spec:
backupName: <backup_resource_name> (2)
restorePVs: true (3)
existingResourcePolicy: update (4)
excludedResources:
- nodes
- events
- events.events.k8s.io
- backups.velero.io
- restores.velero.io
- resticrepositories.velero.io
1 | 将<restore_resource_name> 替换为您的Restore 资源的名称。 |
2 | 将<backup_resource_name> 替换为您的Backup 资源的名称。 |
3 | 启动持久卷 (PV) 及其 Pod 的恢复。 |
4 | 确保用备份的内容覆盖现有对象。 |
您必须在单独的命名空间中创建 |
运行以下命令应用Restore
CR:
$ oc apply -f restore-hosted-cluster.yaml
运行以下命令验证status.phase
的值是否为Completed
:
$ oc get hostedcluster <hosted_cluster_name> -n <hosted_cluster_namespace> -o jsonpath='{.status.phase}'
恢复过程完成后,启动在备份控制平面工作负载期间暂停的HostedCluster
和NodePool
资源的协调。
运行以下命令启动HostedCluster
资源的协调:
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
patch hostedcluster -n <hosted_cluster_namespace> <hosted_cluster_name> \
--type json -p '[{"op": "add", "path": "/spec/pausedUntil", "value": "false"}]'
运行以下命令启动NodePool
资源的协调:
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
patch nodepool -n <hosted_cluster_namespace> <node_pool_name> \
--type json -p '[{"op": "add", "path": "/spec/pausedUntil", "value": "false"}]'
启动在备份控制平面工作负载期间暂停的Agent提供程序资源的协调。
运行以下命令启动AgentCluster
资源的协调:
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
annotate agentcluster -n <hosted_control_plane_namespace> \
cluster.x-k8s.io/paused- --overwrite=true --all
运行以下命令启动AgentMachine
资源的协调:
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
annotate agentmachine -n <hosted_control_plane_namespace> \
cluster.x-k8s.io/paused- --overwrite=true --all
运行以下命令删除HostedCluster
资源中的hypershift.openshift.io/skip-delete-hosted-controlplane-namespace-
注释,以避免手动删除托管控制平面命名空间:
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
annotate hostedcluster -n <hosted_cluster_namespace> <hosted_cluster_name> \
hypershift.openshift.io/skip-delete-hosted-controlplane-namespace- \
--overwrite=true --all
运行以下命令将NodePool
资源扩展到所需的副本数量:
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
scale nodepool -n <hosted_cluster_namespace> <node_pool_name> \
--replicas <replica_count> (1)
1 | 将<replica_count> 替换为整数,例如3 。 |
使用OpenShift数据保护API (OADP)备份和恢复托管集群时,您可以监控和观察该过程。
运行以下命令观察备份过程:
$ watch "oc get backups.velero.io -n openshift-adp <backup_resource_name> -o jsonpath='{.status}'"
运行以下命令观察恢复过程:
$ watch "oc get restores.velero.io -n openshift-adp <backup_resource_name> -o jsonpath='{.status}'"
运行以下命令观察Velero日志:
$ oc logs -n openshift-adp -ldeploy=velero -f
运行以下命令观察所有OADP对象的进度:
$ watch "echo BackupRepositories:;echo;oc get backuprepositories.velero.io -A;echo; echo BackupStorageLocations: ;echo; oc get backupstoragelocations.velero.io -A;echo;echo DataUploads: ;echo;oc get datauploads.velero.io -A;echo;echo DataDownloads: ;echo;oc get datadownloads.velero.io -n openshift-adp; echo;echo VolumeSnapshotLocations: ;echo;oc get volumesnapshotlocations.velero.io -A;echo;echo Backups:;echo;oc get backup -A; echo;echo Restores:;echo;oc get restore -A"
使用OpenShift数据保护API时,您可以使用velero
命令行界面 (CLI) 获取有关Backup
和Restore
资源的更多详细信息。
运行以下命令创建一个别名,以便从容器中使用velero
CLI:
$ alias velero='oc -n openshift-adp exec deployment/velero -c velero -it -- ./velero'
运行以下命令获取您的Restore
自定义资源 (CR) 的详细信息:
$ velero restore describe <restore_resource_name> --details (1)
1 | 将<restore_resource_name> 替换为您的Restore 资源的名称。 |
运行以下命令获取您的Backup
CR 的详细信息:
$ velero restore describe <backup_resource_name> --details (1)
1 | 将<backup_resource_name> 替换为您的Backup 资源的名称。 |