Setup OpenShift GitOps/Argo CD

- Thomas Jungbauer Thomas Jungbauer ( Lastmod: 2024-05-08 ) - 5 min read

If it is not in GitOps, it does not exist“ - is a mantra I hear quite often and also try to practice at customer engagements. The idea is to have Git as the only source of truth on what happens inside the environment. That said, Everything as Code is a practice that treats every aspect of the system as a code. Storing this code in Git provides a shared understanding, traceability and repeatability of changes.

While there are many articles about how to get GitOps into the deployment process of applications, this one rather sets the focus on the cluster configuration and tasks system administrators usually have to do.

Also check out the article GitOps Argo CD

Prerequisites

It all begins with an OpenShift cluster. Such a cluster must be installed and while we will not discuss a bootstrap of the whole cluster … yes, it is possible to even automate the cluster deployment using Advanced Cluster Management as an example, we will simply assume that one cluster is up and running.

For our setup, an OpenShift cluster 4.14 is deployed and we will use the repository OpenShift Cluster Configuration using GitOps to deploy our configuration onto this cluster. This repository shall act as the source of truth for any configuration. In the article Choosing the right Git repository structure I have explained the folder structure I am usually using. As tool I am usually using Helm Charts.

The openshift-clusterconfig-gitops repository heavily uses the Helm Repository found at https://charts.stderr.at/

Deploy OpenShift-GitOps

The first thing we need to do is to deploy OpenShift-GitOps, which is based on the Argo CD project. OpenShift-GitOps comes as an Operator and is available to all OpenShift customers. The Operator will deploy and configure Argo CD and provide several custom resources to configure Argo CD Applications or ApplicationSets for example.

To automate the operator deployment the following shell script can be used: init_GitOps.sh.

This Shell script is the only script that is executed manually. It installs and configures Argo CD. Any other operation on the cluster must then be done using GitOps processes. I am using this to quickly install a new Demo-cluster. There are alternatives and maybe better way, but for my purpose it works pretty well.
  1. Clone the repository to your local machine

    git clone https://github.com/tjungbauer/openshift-clusterconfig-gitops.git
  2. Be sure that you are logged in the the required cluster

    oc whoami --show-server
  3. Execute the init_GitOps.sh

    ./init_GitOps.sh

The script will deploy the operator and configure/patch the Argo CD instance. In addition, it will create the so-called Application of Applications, which acts as an umbrella Application, that automatically creates all other Argo CD Application(Sets). For now, the App of Apps is the only Argo CD Application that automatically synchronizes all changes found in Git. This is for security, purposes so you can test the cluster configuration one after another.

Of course, it is up to you if you want to use the shell script. The Operator can also be installed manually, using Advanced Cluster Manager, or using Platform Operators and installing the Operating during the cluster installation (However, this feature is currently (v4.15) TechPreview)

What will this script do?

I will not de-assemble the script line by line, but in general, the following will happen:

  1. Adding repository https://charts.stderr.at/ and install the Chart openshift-gitops

    This FIRST OpenShift-GitOps will be deployed with cluster-admin privileges since we want to manage the whole cluster configuration. This Argo CD instance should not be used for application deployment. For that, deploy additional instances of GitOps.
  2. Waiting for Deployments to become ready

  3. Deploy the Application of Applications that is responsible for automatically deploying a set of Applications or ApplicationSets (see [The Argo CD Object Manager Application])

The following shows the output of the command:

Logging into Argo CD

At this point, we have GitOps and the "App of Apps" deployed. Argo CD comes with a WebUI and a command line tool. The latter must installed to your local environment. In this article, we will use the WebUI.

To access the WebUI use the applications menu of the top right corner in Openshift.

WebUI Link
Figure 1. Argo CD: WebUI Link

Use the button "Login via OpenShift".

Authentication
Figure 2. Argo CD: Authentication

The Argo CD Resources Manager Application

The Application of Applications (short App of Apps) is called Argo CD Resources Manager and it is the only Argo CD application that is deployed using the init script. This single Argo CD Application has the sole purpose of deploying other Argo CD objects, such as Applications, ApplicationSets and AppProjects.

App of Apps
Figure 3. Argo CD: App of Apps

It synchronizes everything that is found in the repository in the path: base/argocd-resources-manager (main branch)

Whenever you would like to create a new Argo CD application(set) it is supposed to be done using this App-of-Apps or to be more exact: in the path mentioned above.

The App-of-Apps is the only Argo CD Application (at this moment) that has automatic synchronization enabled. Thus any changes in the App-of-Apps will be propagated automatically as soon as GitOps syncs with Git.

The current Applications or ApplicationSets that come with the bootstrap repository are for example:

  • Deployment of Advanced Cluster Security (RHACS)

  • Deployment of Advanced Cluster Management (RHACM)

  • Deployment of basic cluster configuration (i.e. etcd encryption, some UI tweaks …​)

  • Deployment of Compliance Operator

  • and many more.

Check out the deployed Argo CD objects or the openshift-clusterconfig-gitops repository.

A deep dive into the argocd-resources-manager will be topic of a different episode of this serie.