In the previous blog post, we discussed deploying Argo CD on a Kubernetes cluster and explored the fundamentals of application management. This time, we'll leverage Argo CD to deploy the applications from our Kubernetes mini project.
Following are the different components of the project that will get deployed on to a Kubernetes cluster using the Argo CD application resource:
Ingress controller
Prometheus stack
FastAPI web app
FastAPI service monitor
Loki stack
Deploy each of these components by applying the corresponding YAML manifest, following the outlined steps in the GitHub repository mentioned above. After the successful deployment of all components, you can observe them in the Argo CD web UI, as illustrated below.
In this article we will see how to use Git and Argo CD to deploy/ manage applications on your Kubernetes cluster. Before that, what is GitOps? Simply put, Operations driven using Git and CD tools! Following are the major components of GitOps:
Infrastructure as code (IaC)
Merge/ pull requests as change agent
Continuous Delivery tool (Example: Argo CD)
Basically you keep all your application deployment manifests in a Git repository. And, if you like to make changes to your application, you create a merge/ pull request. Once it is approved and merged to the main branch a continuous delivery/ deployment tool like Argo CD will identify that and deploys the latest change to the target Kubernetes cluster. Here I am using a Tanzu Kubernetes Cluster with 1 control plane node and 3 worker nodes. I will be deploying Argo CD as well as my application on this K8s cluster.
❯ kubectl get node NAME STATUS ROLES AGE VERSION gc-control-plane-rhpmq Ready control-plane,master 34d v1.21.6+vmware.1 gc-workers-kfx7q-589888f77b-692n5 Ready <none> 34d v1.21.6+vmware.1 gc-workers-kfx7q-589888f77b-jfzrs Ready <none> 34d v1.21.6+vmware.1 gc-workers-kfx7q-589888f77b-xvjsh Ready <none> 34d v1.21.6+vmware.1
Lets create a namespace first.
❯ kubectl create namespace argocd namespace/argocd created
❯ kubectl apply -f https://gist.githubusercontent.com/vineethac/dafa5b47afd674a1a9f7be2ce773a2bd/raw/4591e837098043b8095a5c48614e1c94b5ca2b44/tkg-psp.yml clusterrole.rbac.authorization.k8s.io/psp:privileged created clusterrolebinding.rbac.authorization.k8s.io/all:psp:privileged created
Next step is to create a repository and add your application yaml files to it. You will also need to create a Argo CD application yaml file, push it to the repository, and then apply the same application yaml file to your cluster.
Following is a screenshot of my repo:
We have the application.yaml file and then inside the dev folder I have two yaml files.
Now, we also have the application yaml file. Make sure to paste your git repo url in the repoURL field.
Lets apply the application yaml manifest on to the Kubernetes cluster and that will connect Argo CD with your git repo.
Note: If you using a private repo, then you need to add your repository to Argo CD first and connect with respective credentials.
Once the application yaml is applied, after few seconds you can see nginx pod and svc getting deployed automatically under myapp namespace.
❯ kubectl get pods,deployment,svc -n myapp NAME READY STATUS RESTARTS AGE pod/my-nginx-74d7c6cb98-tzdfp 1/1 Running 0 2d
NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/my-nginx 1/1 1 1 2d
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/my-nginx ClusterIP 10.109.67.35 <none> 80/TCP 2d
From now on if you like to make changes to your application, say, you want to scale the replicas from 1 to 3, you have to create a merge request or pull request to the repository with the respective change, and once its approved and merged to the main branch Argo CD will automatically detect it and pull it and apply it to your Kubernetes cluster.
Hope it was useful. Cheers!
Reference video by Nana https://twitter.com/Njuchi_