Configuring the hub cluster for backup and restore
You can use GitOps ZTP to configure a set of policies to back up BareMetalHost resources.
This allows you to recover data from a failed hub cluster and deploy a replacement cluster using Red Hat Advanced Cluster Management (RHACM).
-
You have installed the OpenShift CLI (
oc). -
You have logged in as a user with
cluster-adminprivileges.
-
Create a policy to add the
cluster.open-cluster-management.io/backup=cluster-activationlabel to allBareMetalHostresources that have theinfraenvs.agent-install.openshift.iolabel. Save the policy asBareMetalHostBackupPolicy.yaml.The following example adds the
cluster.open-cluster-management.io/backuplabel to allBareMetalHostresources that have theinfraenvs.agent-install.openshift.iolabel:Example PolicyapiVersion: 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 {{- 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: defaultIf you apply the
cluster.open-cluster-management.io/backup: cluster-activationlabel toBareMetalHostresources, the RHACM cluster backs up those resources. You can restore theBareMetalHostresources if the active cluster becomes unavailable, when restoring the hub activation resources. -
Apply the policy by running the following command:
$ oc apply -f BareMetalHostBackupPolicy.yaml
-
Find all
BareMetalHostresources with the labelinfraenvs.agent-install.openshift.ioby running the following command:$ oc get BareMetalHost -A -l infraenvs.agent-install.openshift.ioExample outputNAMESPACE NAME STATE CONSUMER ONLINE ERROR AGE baremetal-ns baremetal-name false 50s -
Verify that the policy has applied the label
cluster.open-cluster-management.io/backup=cluster-activationto all these resources, by running the following command:$ oc get BareMetalHost -A -l infraenvs.agent-install.openshift.io,cluster.open-cluster-management.io/backup=cluster-activationExample outputNAMESPACE NAME STATE CONSUMER ONLINE ERROR AGE baremetal-ns baremetal-name false 50sThe output must show the same list as in the previous step, which listed all
BareMetalHostresources with the labelinfraenvs.agent-install.openshift.io. This confirms that all theBareMetalHostresources with theinfraenvs.agent-install.openshift.iolabel also have thecluster.open-cluster-management.io/backup: cluster-activationlabel.The following example shows a
BareMetalHostresource with theinfraenvs.agent-install.openshift.iolabel. The resource must also have thecluster.open-cluster-management.io/backup: cluster-activationlabel, which was added by the policy created in step 1.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
You can now use Red Hat Advanced Cluster Management to restore a managed cluster.
|
|
When you restore
|