Chapter 11. Creating a sample application
In order to test failover from the Primary managed cluster to the Secondary managed cluster and back again we need a simple application. Use the sample application called busybox as an example.
Procedure
Create a namespace or project on the Hub cluster for a
busyboxsample application.$ oc new-project busybox-sample
NoteA different project name other than
busybox-samplecan be used if desired. Make sure when deploying the sample application via the Advanced Cluster Manager console to use the same project name as what is created in this step.Create DRPlacementControl resource
DRPlacementControl is an API available after the OpenShift DR Hub Operator is installed on the Hub cluster. It is broadly an Advanced Cluster Manager PlacementRule reconciler that orchestrates placement decisions based on data availability across clusters that are part of a DRPolicy.
-
On the Hub cluster, navigate to Installed Operators in the
busybox-sampleproject and click on OpenShift DR Hub Operator. You should see two available APIs, DRPolicy and DRPlacementControl. -
Create an instance for DRPlacementControl and then go to the YAML view. Make sure the
busybox-sampleproject is selected. Save the following YAML to filename
busybox-drpc.yamlafter replacing <cluster1> with the correct name of your managed cluster in Advanced Cluster Manager. ModifydrPolicyRefname for the DRPolicy that has the desired replication interval.apiVersion: ramendr.openshift.io/v1alpha1 kind: DRPlacementControl metadata: labels: app: busybox-sample name: busybox-drpc spec: drPolicyRef: name: odr-policy-5m ## <-- Modify to specify desired DRPolicy and RPO placementRef: kind: PlacementRule name: busybox-placement preferredCluster: <cluster1> pvcSelector: matchLabels: appname: busybox-
Copy the contents of your unique
busybox-drpc.yamlfile into the YAML view (completely replacing original content). Click Create on the YAML view screen.
You can also create this resource using the following CLI command:
$ oc create -f busybox-drpc.yaml -n busybox-sample
Example output:
drplacementcontrol.ramendr.openshift.io/busybox-drpc created
ImportantThis resource must be created in the
busybox-samplenamespace (or whatever namespace you created earlier).
-
On the Hub cluster, navigate to Installed Operators in the
Create Placement Rule resource that defines the target clusters where resource templates can be deployed. Use placement rules to facilitate the multicluster deployment of your applications.
Copy and save the following YAML to filename
busybox-placementrule.yaml.apiVersion: apps.open-cluster-management.io/v1 kind: PlacementRule metadata: labels: app: busybox-sample name: busybox-placement spec: clusterConditions: - status: "True" type: ManagedClusterConditionAvailable clusterReplicas: 1 schedulerName: ramenCreate the Placement Rule resource for the
busybox-sampleapplication.$ oc create -f busybox-placementrule.yaml -n busybox-sample
Example output:
placementrule.apps.open-cluster-management.io/busybox-placement created
ImportantThis resource must be created in the
busybox-samplenamespace (or whatever namespace you created earlier).
Create sample application using RHACM console
Log in to the RHACM console using your OpenShift credentials if not already logged in.
$ oc get route multicloud-console -n open-cluster-management -o jsonpath --template="https://{.spec.host}/multicloud/applications{'\n'}"Example Output:
https://multicloud-console.apps.perf3.example.com/multicloud/applications
- Navigate to Applications and click Create application.
- Select type as Subscription.
-
Enter your application Name (for example,
busybox) and Namespace (for example,busybox-sample). -
In Repository location for resources section, select Repository type
Git. Enter the Git repository URL for the sample application, the github Branch and Path where the resources
busyboxPod and PVC will be created.Use the sample application repository as
https://github.com/RamenDR/ocm-ramen-sampleswhere the Branch ismainand Path isbusybox-odr.ImportantMake sure that the new StorageClass
ocs-storagecluster-ceph-rbdmirroris created as detailed in section Create Mirroring StorageClass resource before proceeding.Verify that it is created using the following command:
oc get storageclass | grep rbdmirror | awk '{print $1}'Example output:
ocs-storagecluster-ceph-rbdmirror
- Scroll down the form to the section Select clusters to deploy to and click Select an existing placement configuration.
-
Select an Existing Placement Rule (for example,
busybox-placement) from the drop-down list. Click Save.
On the follow-on screen scroll to the bottom. You should see that there are all Green checkmarks on the application topology.
NoteTo get more information, click on any of the topology elements and a window will appear on the right of the topology view.
Verify the sample application deployment and replication.
Now that the
busyboxapplication has been deployed to your preferred Cluster (specified in the DRPlacementControl) the deployment can be validated.Login to your managed cluster where
busyboxwas deployed by RHACM.$ oc get pods,pvc -n busybox-sample
Example output:
NAME READY STATUS RESTARTS AGE pod/busybox 1/1 Running 0 6m NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE persistentvolumeclaim/busybox-pvc Bound pvc-a56c138a-a1a9-4465-927f-af02afbbff37 1Gi RWO ocs-storagecluster-ceph-rbd 6m
Verify that the replication resources are also created for the
busyboxPVC.$ oc get volumereplication,volumereplicationgroup -n busybox-sample
Example output:
NAME AGE VOLUMEREPLICATIONCLASS PVCNAME DESIREDSTATE CURRENTSTATE volumereplication.replication.storage.openshift.io/busybox-pvc 6m odf-rbd-volumereplicationclass busybox-pvc primary Primary NAME AGE volumereplicationgroup.ramendr.openshift.io/busybox-drpc 6m
Verify that the
busyboxvolume has been replicated to the alternate cluster by running the following command on both the Primary managed cluster and the Secondary managed cluster.$ oc get cephblockpool ocs-storagecluster-cephblockpool -n openshift-storage -o jsonpath='{.status.mirroringStatus.summary}{"\n"}'Example output:
{"daemon_health":"OK","health":"OK","image_health":"OK","states":{"replaying":2}}NoteBoth managed clusters should have the exact same output with a new status of
"states":{"replaying":2}`.
11.1. Deleting sample application
You can delete the sample application busybox using the RHACM console.
The instructions to delete the sample application should not be executed until the failover and failback (relocate) testing is completed and the application is ready to be removed from RHACM and the managed clusters.
Procedure
- On the RHACM console, navigate to Applications.
-
Search for the sample application to be deleted (for example,
busybox). - Click the Action Menu (⋮) next to the application you want to delete.
Click Delete application.
When Delete application is selected a new screen will appear asking if the application related resources should also be deleted.
- Select Remove application related resources checkbox to delete the Subscription and PlacementRule.
- Click Delete. This will delete the busybox application on the Primary managed cluster (or whatever cluster the application was running on).
In addition to the resources deleted using the RHACM console, the
DRPlacementControlmust also be deleted immediately after deleting thebusyboxapplication.-
Login to the OpenShift Web console for the Hub cluster and navigate to Installed Operators for the project
busybox-sample. - Click OpenShift DR Hub Operator and then click DRPlacementControl tab.
-
Click the Action Menu (⋮) next to the
busyboxapplication DRPlacementControl that you want to delete. - Click Delete DRPlacementControl.
- Click Delete.
-
Login to the OpenShift Web console for the Hub cluster and navigate to Installed Operators for the project
This process can be used to delete any application with a DRPlacementControl resource. The DRPlacementControl resource can also be deleted in the application namespace using CLI.