Introduction

Using OpenShift GitOps, you can achieve consistency between different clusters / environments for you application releases, across development, testing, production etc. OpenShift GitOps enables a declerative approach to managing your OpenShift environment using Git Sources code repositories as the “version of truth” for your cluster configuration and application deployment.

ArgoCD is the key community project them empowers the maintenance of cluster resources in OpenShift GitOps.

In this blog, we will configure OpenShift GitOps and deploy a simple application to our OpenShift environment using ArgoCD.

Getting set up

The firts part of the process is to enable the OpenShift GitOps operator, from the operator store in OpenShift. This can be done through the OpenShift console, but we’ll do it using the cli instead.

Make sure you’re logged into your OpenShift environment:

oc status

And once you’re ready we will create a new project / namespace into which we will deploy ArgoCD and the associated resources.

oc new-project gitops

To install the operator, we first create an operator group:

cat << EOF > gitops.yaml
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
  name: gitops
  namespace: gitops
spec:
  targetNamespaces:
  - gitops
EOF
oc apply -f gitops.yaml

And then create a subscription to the OpenShift GitOps operator:

cat << EOF > subscription.yaml
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: openshift-gitops
  namespace: openshift-operators 
spec:
  channel: stable 
  name: openshift-gitops-operator 
  source: redhat-operators 
  sourceNamespace: openshift-marketplace 
EOF
oc apply -f subscription.yaml

Finally, we’ll create an instance of ArgoCD itself using the OpenShift GitOps operator:

cat << EOF > argocd.yaml
apiVersion: argoproj.io/v1alpha1
kind: ArgoCD
metadata:
  name: argocd
spec:
  server:
    route:
      enabled: true
EOF
oc apply -f argocd.yaml

This will take a short while as the container images are pulled down and the relevant pods started. You can check on the process using the following:

oc get pods -n gitops -w

Once all pods are successfully deployed, we need to get the admin password for the admin user to log into ArgoCD. Run the following command:

oc get secret argocd-cluster -o jsonpath="{.data['admin\.password']}" | base64 -d

Now lets grab the route to the UI:

oc get route

Copy and paste that into your browser instance and login using the username ‘admin’ and the password from the previous step.

Creating our ArgoCD project

Now we’ll create an ArgoCD project to deploy our application into. Firstly, we need to download the cli tool for ArgoCD which can be obtained from the github project directly.

At the time of writing, the latest cli version is v2.2.5

wget https://github.com/argoproj/argo-cd/releases/download/v2.2.5/argocd-linux-amd64
sudo mv argocd-linux-amd64 /usr/local/bin/argocd
sudo chmod +x /usr/local/bin/argocd
argocd version

Next, we’ll login using the cli. You will be prompted for the username (which is ‘admin’) and a password which you revealed earlier.

ARGOCD_ROUTE=$(oc -n gitops get route argocd-server -o jsonpath='{.spec.host}')
argocd login $ARGOCD_ROUTE

Once logged in, we’ll create a project using the cli to deploy our application to:

argocd proj create hellogo
cat << EOF > argo-app.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: hellogo
spec:
  destination:
    name: ''
    namespace: gitops
    server: 'https://kubernetes.default.svc'
  source:
    path: .
    repoURL: 'https://github.com/mkimberley/go_helloweb'
    targetRevision: HEAD
    helm:
      valueFiles: ['values.yaml']
  project: default
  syncPolicy:
    automated:
      prune: false
      selfHeal: false
EOF

And apply the manifest to OpenShift:

oc apply -f argo-app.yaml

The application manifest will be built within ArgoCD. Once that happens, ArgoCD will clone down the git repository which contains a helm chart to deploy the pods, services etc on our OpenShift Environment. It will take some time to deploy as the container image is pulled down and the resouces built within OpenShift. You can check on the application history using the ArgoCD cli:

argocd app history hellogo

Once the simple application is deployed on our cluster, we can test it with a simple curl command:

oc expose svc/helloweb-chart -n gitops
HELLOGO_ROUTE=$(oc -n gitops get route helloweb-chart -o jsonpath='{.spec.host}')
curl $HELLOGO_ROUTE/$(whoami) -w "\n"

This should output “Hello there, !” (with your username)

At this point you have successfully deployed ArgoCD onto your OpenShift environment using the argocd cli, and deployed a very web webb application server using an application manifest.