Manage OpenShift virtual machines with GitOps

Learn how to utilize GitOps in OpenShift to manage your virtual machines (VMs).

The first step of this process is to connect the Git repository to the OpenShift Argo CD instance, where we’ll store the configuration files for the OpenShift VMs.

In order to get full benefit from taking this lesson, you need to:

  • A GitHub account.
  • An OpenShift Cluster with the Red Hat OpenShift Virtualization and Red Hat OpenShift GitOps operators installed and configured. 
    • You will also need to configure Argo CD within GitOps—for this demonstration, all of the default settings have been used for Argo.

In this lesson, you will:

  • Connect and configure the external repository.

Connect the Git repository

One of the operators available in your subscription is Red Hat OpenShift GitOps. It’s easily available for installation in the Operators menu in the OpenShift user interface (UI). There are no special steps involved here, and once the installation is complete, the Argo CD instance is created with default options. 

There are a couple of ways to access the Argo CD UI. You can click the grid of nine squares in the upper right-hand corner of the OpenShift banner as shown in Figure 1. If you only have the command-line interface (CLI), you can use oc get route -n openshift-gitops as well.

Click the grid of squares in the upper right corner of the OpenShift banner to reveal a menu, then select Cluster Argo CD.
Figure 1: How to find the Argo CD web console from the OpenShift UI.

For our demonstration, we’re using a public repository that has been configured in Argo CD to provide the needed files. Adding the repo into Argo is simple and can be accomplished via the Argo site we found above under the Settings > Repositories link, or via the CLI as shown in the examples below. The first command logs you into your Argo CD instance using the - -insecure option due to the test environment only having a self-signed certificate. The second adds the repository to the Argo CD instance. See below:

argocd login --insecure --username=<your username, we’ve used admin> openshift-gitops-server-openshift-gitops.apps.beehive.example.org
Password:  <your password>
'admin:login' logged in successfully
Context 'openshift-gitops-server-openshift-gitops.apps.beehive.example.org' updated
argocd repo add <your github repository url>
Repository ''<your github repository url>” added

Note that if you plan to use a namespace that is different from the default one that OpenShift Gitops creates, you’ll need to apply a label to the namespace in order to let Argo CD acquire administrative privileges in it. The following command accomplishes this: 

oc label namespace <namespace> <label> 

For example, the one we’re using would be: oc label namespace beehive-virtual-machines argocd.argoproj.io/managed-by=openshift-gitops

To verify that the repository was added correctly, run the command below. Your list will vary depending on what was added, but this shows the repositories that are configured in our test cluster:

argocd repo list
TYPE        REPO                                                        INSECURE   STATUS 
git         https://github.com/baromm14/ocp-virt-gitops.git             false      Successful

The repository is now configured. In Lesson 2, we will populate the repository with the files necessary to create and manage our virtual machines. 

Previous resource
Overview: Manage OpenShift virtual machines with GitOps
Next resource
Create and customize virtual machine files within the repository