Cloud Experts Documentation

Demonstrate GitOps on Managed OpenShift with ArgoCD

This content is authored by Red Hat experts, but has not yet been tested on every supported configuration.

Author: Steve Mirmanexternal link (opens in new tab)

Video Walkthrough

If you prefer a more visual medium, you can watch Steve Mirmanexternal link (opens in new tab) walk through this quickstart on YouTubeexternal link (opens in new tab) .


The purpose of this document is to help you get OpenShift GitOps running in your cluster, including deploying a sample application and demonstrating how ArgoCD ensures environment consistency.

This demo assumes you have a Managed OpenShift Cluster available and cluster-admin rights.


GitHub resources referenced in the demo:

Required command line (CLI) tools


Environment Set Up

Install the OpenShift GitOps operator

  1. Install the OpenShift GitOps operator from the Operator Hub

    screenshot of GitOps install

Pull files from GitHub

  1. Clone the gitops-demo GitHub repository to your local machine

    git clone https://github.com/rh-mobb/gitops-demo gitops
    
  2. Export your local path to the GitHub files

    export GITOPS_HOME="$(pwd)/gitops"
    cd $GITOPS_HOME
    

Log in to OpenShift via the CLI

  1. Retrieve the login command from the OpenShift console
    screenshot of login

  2. Enter the command in your terminal to authenticate with the OpenShift CLI (oc)

    Output should appear similar to:

    Logged into "https://<YOUR-INSTANCE>.openshiftapps.com:6443" as "<YOUR-ID>" using the token provided.
    

Deploy the ArgoCD Project

Create a new OpenShift project

  1. Create a new OpenShift project called gitops
    oc new-project gitops
    

Edit service account permissions

  1. Add cluster-admin rights to the openshift-gitops-argocd-application-controller service account in the openshift-gitops namespace
    oc adm policy add-cluster-role-to-user cluster-admin -z openshift-gitops-argocd-application-controller -n openshift-gitops
    

Log in to ArgoCD

  1. Retrieve ArgoCD URL:

    argoURL=$(oc get route openshift-gitops-server -n openshift-gitops -o jsonpath='{.spec.host}{"\n"}')
    echo $argoURL
    
  2. Retrieve ArgoCD Password:

    argoPass=$(oc get secret/openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d)
    echo $argoPass
    
  3. In a browser, navigate to the ArgoCD console using the $argoURL value returned above
    screenshot of argocd1

  4. Log in with the user name admin and the password returned as $argoPass above
    screenshot of argocd2

    Optional step if you prefer CLI access Login to the CLI:

    argocd login --insecure --grpc-web $argoURL  --username admin --password $argoPass
    

Deploy the ArgoCD project

  1. Use kubectl to apply the bgd-app.yaml file

    kubectl apply -f documentation/modules/ROOT/examples/bgd-app/bgd-app.yaml
    

    The bgd-app.yaml file defines several things, including the repo location for the gitops-bgd-app application
    screenshot of bgd-app-yaml

  2. Check the rollout running the following command:

    kubectl rollout status deploy/bgd -n bgd
    
  3. Once the rollout is complete get the route to the application

    oc get route bgd -n bgd -o jsonpath='{.spec.host}{"\n"}'
    
  4. In your browser, paste the route to open the application
    screenshot of app_blue

  5. Go back to your ArgoCD window and verify the configuration shows there as well
    screenshot of argo_app1

  6. Exploring the application in ArgoCD, you can see all the components are green (synchronized)
    screenshot of argo_sync

Deploy a change to the application

  1. In the terminal, enter the following command which will introduce a chance into the bgd application

    kubectl -n bgd patch deploy/bgd --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/env/0/value", "value":"green"}]'
    
  2. Go back to your ArgoCD window. The application should no longer be synchronized
    screenshot of argo_sync

  3. Refresh the bgd application window and notice the change in box color
    screenshot of bgd_green

    The new deployment changed the box from blue to green, but only within OpenShift, not in the source code repository

Synchronize the application

  1. In the ArgoCD console, click the SYNC button to re-synchronize the bgd application with the approved configuration in the source code repository
    screenshot of sync_bgd

  2. Refresh the bgd application window and notice the change in box color
    screenshot of app_blue

Details from GitHub perspective

TBD

Interested in contributing to these docs?

Collaboration drives progress. Help improve our documentation The Red Hat Way.

Red Hat logo LinkedIn YouTube Facebook Twitter

Products

Tools

Try, buy & sell

Communicate

About Red Hat

We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Subscribe to our newsletter, Red Hat Shares

Sign up now
© 2023 Red Hat, Inc.