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 Mirman
Video Walkthrough
If you prefer a more visual medium, you can watch Steve Mirman walk through this quickstart on YouTube .
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:
- BGD Application:
gitops-bgd-app
- OpenShift / ArgoCD configuration: gitops-demo
Required command line (CLI) tools
Environment Set Up
Install the OpenShift GitOps operator
Install the OpenShift GitOps operator from the Operator Hub
Pull files from GitHub
Clone the
gitops-demo
GitHub repository to your local machinegit clone https://github.com/rh-mobb/gitops-demo gitops
CopyExport your local path to the GitHub files
export GITOPS_HOME="$(pwd)/gitops" cd $GITOPS_HOME
Copy
Log in to OpenShift via the CLI
Retrieve the login command from the OpenShift console
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.
Copy
Deploy the ArgoCD Project
Create a new OpenShift project
- Create a new OpenShift project called gitops
oc new-project gitops
Copy
Edit service account permissions
- Add cluster-admin rights to the
openshift-gitops-argocd-application-controller
service account in the openshift-gitops namespaceoc adm policy add-cluster-role-to-user cluster-admin -z openshift-gitops-argocd-application-controller -n openshift-gitops
Copy
Log in to ArgoCD
Retrieve ArgoCD URL:
argoURL=$(oc get route openshift-gitops-server -n openshift-gitops -o jsonpath='{.spec.host}{"\n"}') echo $argoURL
CopyRetrieve ArgoCD Password:
argoPass=$(oc get secret/openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d) echo $argoPass
CopyIn a browser, navigate to the ArgoCD console using the
$argoURL
value returned aboveLog in with the user name admin and the password returned as
$argoPass
aboveOptional step if you prefer CLI access Login to the CLI:
argocd login --insecure --grpc-web $argoURL --username admin --password $argoPass
Copy
Deploy the ArgoCD project
Use
kubectl
to apply thebgd-app.yaml
filekubectl apply -f documentation/modules/ROOT/examples/bgd-app/bgd-app.yaml
CopyThe bgd-app.yaml file defines several things, including the repo location for the
gitops-bgd-app
applicationCheck the rollout running the following command:
kubectl rollout status deploy/bgd -n bgd
CopyOnce the rollout is complete get the route to the application
oc get route bgd -n bgd -o jsonpath='{.spec.host}{"\n"}'
CopyIn your browser, paste the route to open the application
Go back to your ArgoCD window and verify the configuration shows there as well
Exploring the application in ArgoCD, you can see all the components are green (synchronized)
Deploy a change to the application
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"}]'
CopyGo back to your ArgoCD window. The application should no longer be synchronized
Refresh the bgd application window and notice the change in box color
The new deployment changed the box from blue to green, but only within OpenShift, not in the source code repository
Synchronize the application
In the ArgoCD console, click the
SYNC
button to re-synchronize the bgd application with the approved configuration in the source code repositoryRefresh the bgd application window and notice the change in box color