2.11. 为备份和恢复配置 hub 集群
您可以使用 GitOps ZTP 配置一组策略来备份 BareMetalHost
资源。这可让您从失败的 hub 集群中恢复数据,并使用 Red Hat Advanced Cluster Management (RHACM)部署替换集群。
先决条件
-
已安装 OpenShift CLI(
oc
)。 -
您已以具有
cluster-admin
权限的用户身份登录。
流程
创建一个策略,将
cluster.open-cluster-management.io/backup=cluster-activation
标签添加到具有infraenvs.agent-install.openshift.io
标签的所有BareMetalHost
资源中。将策略保存为BareMetalHostBackupPolicy.yaml
。以下示例将
cluster.open-cluster-management.io/backup
标签添加到具有infraenvs.agent-install.openshift.io
标签的所有BareMetalHost
资源中:策略示例
apiVersion: policy.open-cluster-management.io/v1 kind: Policy metadata: name: bmh-cluster-activation-label annotations: policy.open-cluster-management.io/description: Policy used to add the cluster.open-cluster-management.io/backup=cluster-activation label to all BareMetalHost resources spec: disabled: false policy-templates: - objectDefinition: apiVersion: policy.open-cluster-management.io/v1 kind: ConfigurationPolicy metadata: name: set-bmh-backup-label spec: object-templates-raw: | {{- /* Set cluster-activation label on all BMH resources */ -}} {{- $infra_label := "infraenvs.agent-install.openshift.io" }} {{- range $bmh := (lookup "metal3.io/v1alpha1" "BareMetalHost" "" "" $infra_label).items }} - complianceType: musthave objectDefinition: kind: BareMetalHost apiVersion: metal3.io/v1alpha1 metadata: name: {{ $bmh.metadata.name }} namespace: {{ $bmh.metadata.namespace }} labels: cluster.open-cluster-management.io/backup: cluster-activation 1 {{- end }} remediationAction: enforce severity: high --- apiVersion: cluster.open-cluster-management.io/v1beta1 kind: Placement metadata: name: bmh-cluster-activation-label-pr spec: predicates: - requiredClusterSelector: labelSelector: matchExpressions: - key: name operator: In values: - local-cluster --- apiVersion: policy.open-cluster-management.io/v1 kind: PlacementBinding metadata: name: bmh-cluster-activation-label-binding placementRef: name: bmh-cluster-activation-label-pr apiGroup: cluster.open-cluster-management.io kind: Placement subjects: - name: bmh-cluster-activation-label apiGroup: policy.open-cluster-management.io kind: Policy --- apiVersion: cluster.open-cluster-management.io/v1beta2 kind: ManagedClusterSetBinding metadata: name: default namespace: default spec: clusterSet: default
- 1
- 如果您将
cluster.open-cluster-management.io/backup: cluster-activation
标签应用到BareMetalHost
资源,RHACM 集群备份这些资源。如果在恢复 hub 激活资源时,如果活跃的集群不可用,可以恢复BareMetalHost
资源。
运行以下命令来应用策略:
$ oc apply -f BareMetalHostBackupPolicy.yaml
验证
运行以下命令,使用标签
infraenvs.agent-install.openshift.io
查找所有BareMetalHost
资源:$ oc get BareMetalHost -A -l infraenvs.agent-install.openshift.io
输出示例
NAMESPACE NAME STATE CONSUMER ONLINE ERROR AGE baremetal-ns baremetal-name false 50s
运行以下命令,验证策略是否已将标签
cluster.open-cluster-management.io/backup=cluster-activation
应用到所有这些资源:$ oc get BareMetalHost -A -l infraenvs.agent-install.openshift.io,cluster.open-cluster-management.io/backup=cluster-activation
输出示例
NAMESPACE NAME STATE CONSUMER ONLINE ERROR AGE baremetal-ns baremetal-name false 50s
输出必须显示与上一步中的相同列表,该列表列出了带有标签
infraenvs.agent-install.openshift.io
的所有BareMetalHost
资源。这确认所有带有infraenvs.agent-install.openshift.io
标签的BareMetalHost
资源也具有cluster.open-cluster-management.io/backup: cluster-activation
标签。以下示例显示了带有
infraenvs.agent-install.openshift.io
标签的BareMetalHost
资源。资源还必须有cluster.open-cluster-management.io/backup: cluster-activation
标签,该标签由您创建的策略添加。apiVersion: metal3.io/v1alpha1 kind: BareMetalHost metadata: labels: cluster.open-cluster-management.io/backup: cluster-activation infraenvs.agent-install.openshift.io: value name: baremetal-name namespace: baremetal-ns
现在,您可以使用 Red Hat Advanced Cluster Management 恢复受管集群。
当您将 BareMetalHosts
资源作为恢复集群激活数据的一部分恢复时,您必须恢复 BareMetalHosts
状态。以下 RHACM Restore
资源示例恢复激活资源,包括 BareMetalHosts
,同时还恢复 BareMetalHosts
资源的状态:
apiVersion: cluster.open-cluster-management.io/v1beta1 kind: Restore metadata: name: restore-acm-bmh namespace: open-cluster-management-backup spec: cleanupBeforeRestore: CleanupRestored veleroManagedClustersBackupName: latest 1 veleroCredentialsBackupName: latest veleroResourcesBackupName: latest restoreStatus: includedResources: - BareMetalHosts2
其他资源