In this blog, we will show you how to take an existing application and adopt it for management by Red Hat Advanced Cluster Management. Red Hat Advanced Cluster Management v2.1 brings us four pillars of management that cover what you need to manage enterprise OpenShift clusters at scale: cluster lifecycle; application lifecycle; governance, risk & compliance; and observability.
One piece of the puzzle when importing existing clusters is the currently deployed workloads on those clusters. With our replace capabilities, an applications manifest can be stored in Git, and then the application is adopted by the Advanced Cluster Management application lifecycle. You can then begin to manage your applications through GitOps and the application console.
In this example, we will use a sample application that you will deploy with the
kubectl apply command, and then adopt into the application console.
- You need a managed OpenShift cluster.
- You need a Red Hat Advanced Cluster Management hub cluster.
- Ensure you have an application that runs on Kubernetes.
- You also need GitHub access.
Apply an application
Applying the application manually is easy. See the procedure:
- Log into the managed OpenShift cluster.
- Fork the following demonstration repository: Demo GitOps.
- Clone that repo to the system where you are connecting to the managed OpenShift cluster.
- Create the namespace
oc new-project nginx.
- Apply the basic application with
oc apply -k placement/nginx.
Now we have an application manifest applied manually to the managed cluster. This application consists of a deployment with a replica set, a service, and a route.
We adopt the application with Red Hat Advanced Cluster Management application lifecycle capabilities. Subscriptions are used for delivering and maintaining applications. To accomplish the adoption, you must build a copy of the application manifest in Git. If the application did not originate from a repository, using the Kubernetes CLI, extract the manifest information for each resource in the application. In our example, we use the following commands:
kubectl get deploy nginx-placement -o yaml > deployment.yaml
kubectl get route nginx -o yaml > route.yaml
kubectl get service placement-nginx-service > service.yaml
If you’d like to use
kustomize, create the following
This all exists in the fork for this exercise, but if you are adopting a new application, you would then commit the resource YAML files to your Git repository.
With the artifacts in place in Git, we will initialize the application subscription for our managed cluster, which will adopt management of the application into Red Hat Advanced Cluster Management.
Adopting an application
By default, a subscription cannot apply resources from the source repository to the existing resources on the cluster if the resources are not created by the subscription.
In this exercise, we are going to apply the application artifacts from the Git repository to the cluster where the application artifacts already exist by using a subscription. In order to alter the default subscription behavior to overwrite existing resources, you need to log into Red Hat Advanced Cluster Management as a subscription administrator. See the following procedure to set up that role:
- Log into the hub cluster using CLI.
oc edit clusterrolebinding open-cluster-management:subscription-adminand add a user or a group subject. See the following example:
- apiGroup: rbac.authorization.k8s.io
- Save changes.
- Log in to the Red Hat Advanced Cluster Management console as the subscription administrator.
Now you are ready to create:
- Navigate to the Application overview page.
- Select Create application.
- Give your application a Name and choose or create a Namespace that matches where your existing application is deployed.
- Select the Git Repository type.
- Choose or enter your URL for the repository (forked repository URL for this exercise).
- Choose the appropriate Branch and enter the path
- Check the Merge updates box, and flip the YAML: On switch at the top of the page.
- On the right pane, in the Application YAML editor, modify the line:
apps.open-cluster-management.io/reconcile-option: mergeand change
- Select clusters to deploy to by providing a Label and Value that match the managed cluster where you previously deployed the application. Example:
- Click Save and you will be taken to the Topology.
The Topology shows the way Red Hat Advanced Cluster Management sees your manifest defined in Git. The nodes will show the states of each resource as they are adopted by the remote cluster. If you watch the resources, you will see that annotations are added to all the resources defined on the managed cluster, which is how Red Hat Advanced Cluster Management identifies the application resources under management.
Once all the nodes move to a successful states (green check mark), the application is under Red Hat Advanced Cluster Management control. Any new changes to the manifest in Git will result in the application being modified accordingly by the Advanced Cluster Management subscription.
You can validate this by modifying the image version found in the
1.16.1. This will trigger the
nginx app to be upgraded, and the console will display the new version.
This opens exciting possibilities when using Red Hat Advanced Cluster Management. Bringing existing Kubernetes applications onboard from your imported clusters allows you to create a central management strategy and provides a single pane of glass to view all your applications. This adoption capability allows integration of Red Hat Advanced Cluster Management into your existing Kubernetes infrastructure, allowing the evolution to a GitOps style of application management.