Try GitOps on your laptop

Try GitOps on your laptop

In this article, I share my basic experience about how to connect Github, ArgoCD and Openshift, and deploy a helm chart application using this GitOps model.

This Lab covers some basics of the GitOps tools, of course it seems basic for DevOps Gurus, but for me it is a good approach to understand in a practical way how these DevOps tools (islands) connect to each other and how cool is it to work with these tools. So I decided to share what I've done after playing around with these tools :). Let's start.

The main goal of this LAB is to deploy an application and check the changes happen on Openshift when an update happens to the app code on GitHub.

The main tools to use are:

Redhat Openshift Local, Helm Chart, ArgoCD and GitHub

Install Red?Hat OpenShift Local (formerly Red Hat CodeReady Containers)

Follow these easy steps to setup Openshift Locally on your machine https://access.redhat.com/documentation/en-us/red_hat_openshift_local/2.5/html/getting_started_guide/installation_gsg#doc-wrapper ?

Install Helm on your machine (Optional)

Only to get familiar with helm and create test helm charts to use later https://helm.sh/docs/intro/install/

Prepare GitHub repository

  • Create your own repo on Github or use my example file below (A Helm chart that creates a ConfigMap only)
  • Make sure the repo is public.
  • Copy helm chart files to the repo.
  • As example, you may refer to https://github.com/mgamalelnaggar/helm-first-chart

Install ArgoCD on OCP

  • Create new namespace for ArgoCD

oc create namespace argocd        

  • Apply the ArgoCD Manifest on OpenShift

oc apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml        

Due to some issues with privileges, download the install.yaml file first and search for below lines and remove them, then apply the file to install the ArgoCD


wget https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

vi install.yaml

remove "securityContext:" and the two lines below

Save the file and run 

oc apply -f install.yaml        

  • Wait till all containers become in running state?

oc get pods -n argocd??        

  • Expose ArgoCD Server using OpenShift Route. We need to Patch ArgoCD Server deployment on OpenShift for the service to be exposed through the OpenShift Route:

oc -n argocd patch deployment argocd-server -p '{"spec":{"template":{"spec":{"$setElementOrder/containers":[{"name":"argocd-server"}],"containers":[{"command":["argocd-server","--insecure","--staticassets","/shared/app"],"name":"argocd-server"}]}}}}

oc -n argocd create route edge argocd-server --service=argocd-server --port=http --insecure-policy=Redirect'?        

  • Login to ArgoCD webpage via the url generated after exposing the service via route (https://argocd-server-argocd.apps-crc.testing)

Username: admin
        

  • Retrieve admin password to use for logging to the UI

oc -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo?        

Link ArgoCD with GitHub and create an application

  • Create new application

From UI, click on new App and fill below fields

No alt text provided for this image

Application Name: <app-name>

Project Name: default

SOURCE

Repository URL: <Github repo link>?

????????????????To get the repo link, make sure you click on the repo name on Github, click on the green button on the right named "code", then copy the HTTPS URL

Revision: HEAD

Path: <path to folder holding files>

DESTINATION:

Cluster URL: Change the drop down menu from URL to NAME, then write "in-cluster"

Namespace: <namespace on openshift cluster>

Click on CREATE and enjoy playing with Git and ArgoCD

  • Refresh the App to fetch the files from Git. After refreshing, the status should be OutOfSync.
  • Once you click on Synchronize, the changes will get reflected right away on the Openshift.
  • You may choose to synchronize automatically, so once the status become OutOfSync, ArgoCD will do the changes effectively to OCP.

I hope it was informative to you.

Your feedback will be more than appreciated.

Thanks

Enjoy :)

要查看或添加评论,请登录

社区洞察

其他会员也浏览了