Argo CD — A GitOps Tool for Continuous Delivery

Sharadhi S S
6 min readJul 8, 2022

--

Before learning about Argo CD, let’s first know about how CD is implemented commonly. Say we have microservices, which need to be deployed in the Kubernetes cluster. Whenever we commit the application code, it will trigger the CI pipeline, test the changes, build the image, and push the image to any repository like jFrog, GCR, ECR, etc.

After pushing it to the repository, we update the Kubernetes deployment file with a new image tag. Then we apply the changes to the Kubernetes cluster.

Typical Software Delivery Pipeline

Challenges in this approach

  • Installing and setting up the kubectl CLI and also installing helm to execute YAML files.
  • By installing and integrating a lot of tools, we may need to set up configurations for each of these in the CI tool. This will become a security challenge as we may need to give credentials to third-party tools.
  • Once CI/CD tool deploys the application, it will not show the status of execution like whether pods are healthy or failed.

To overcome these problems, Argo CD was introduced. Argo CD is a GitOps tool built into the Kubernetes cluster based on the pull mechanism.

What is Argo CD?

Argo CD is a container native K8 engine for orchestrating jobs on Kubernetes. Here the jobs will run entirely on Kubernetes and instead of accessing the cluster outside using a third-party tool, we install Argo CD, which will be installed as part of the cluster.

Argo CD Image

By using Argo CD, we will be keeping the application repository and configuration/manifests files in different repositories. As part of a cluster, Argo CD will be keeping track of the desired state, and whenever there are changes in the repository manifest files, Argo CD pulls the changes to the cluster, applies them, and achieve the target state.

Let us now know about the Architecture of Argo CD

Argo CD uses git repositories as the source of truth for the desired state of applications and the target deployment environments. Kubernetes manifests can be specified as YAML files or Helm packages. Argo CD automates the synchronization of the desired application state with each specified target environment.

The architecture of Argo CD

Whenever we commit to the git configuration repository, Argo CD will be notified and it will check what has changed. Argo CD will sync the current state to the desired state. Argo CD achieves the desired state automatically.

Benefits of Argo CD

  • We will be having a separate repository for application and configuration code.
  • We also don’t need to apply the changes manually to the cluster.
  • Argo CD will be watching the changes in both cluster and GIT. So even if someone changes cluster configurations manually, Argo CD will give priority to GIT first and changes configurations as provided in git.
  • We can have an easy rollback.
  • We will be having cluster configuration in GIT. Even if the cluster crashes, we can set it up easily.
  • As Argo CD is an extension of K8 API, it uses existing functionalities like ETCD, and controller, it gives visibility to clusters and real-time updates of app state using UI.

Installation and application.yaml file in Argo CD

Pre-requisites:

  • Installed kubectl command-line tool
  • Have a kubeconfig file (default location is ~/.kube/config).
  • Minikube installed up and running

As mentioned argocd will be installed inside the cluster. To install Argo CD first, we need to create namespace argocd. The Argo CD will run on this namespace. The command to create argocd namespace is this.

kubectl create namespace argocd

After this namespace creation, install the Argo CD stable version using this command.

kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.4.7/manifests/install.yaml

This will install argocd. Once you are done with installing just run the following command to list the pods.

kubectl get pods -n argocd

The output of this command will be something like this:

Pods of Argo CD

In the above diagram,

  • argocd-app-controller -> This pod monitors running applications and is responsible for comparing the current state against the desired state.
  • Dex-server -> This pod helps in authentication and configuration settings of Argo.
  • Repo-server -> This holds and maintains the local cache of the git repository. It contains application and Kubernetes manifest files.
  • Redis -> This pod is used for cache
  • Argocd-server -> This pod exposes API by using web UI, and CLI.

If you list the services in Kubernetes:

kubectl get svc -n argocd

It will print Argo-server running on port 443. To access the argocd UI run the following command. This command will map port 443 of the cluster to 8080 on localhost.

kubectl port-forward svc/argocd-server -n argocd 8080:443
Port-forwarding to access Argo CD UI

This will open up the UI at https://localhost:8080. This will open a login page first. The username is admin and to get the password run the following command.

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

The UI will look like this:

User Interface of Argo CD

Now the installation of the Argo CD is complete. Let us deploy a sample application, that will be maintained by Argo CD.

Deploy a Sample Application to Argo CD

For deploying the sample application, we will make use of the below repository of Argo CD.

Here we will make use of the folder guestbook. We will create Argo CD manifest file application.yaml file. We extend Kubernetes API with CRD. The main resource is application.yaml file, as mentioned below.

application.yaml file for Argo CD

In this file,

  • Here we create a CRD of the application. The important thing in this file is SOURCE and DESTINATION.
  • Source refers to the repository to which the Argo CD should listen.
  • The Destination is the Kubernetes cluster. In here cluster is running in minikube that cluster URL is given.
  • Another parameter is sync policy, here we mention creating a namespace if not exist.
  • SelfHeal is an auto-healing mechanism to undo the manual changes and prune is set to true so that we cannot delete the resources.

We should run the following command to apply application CRD to tell Argo CD which repository to sync with:

kubectl apply -f application.yaml -n argocd

This will be the Argo CD UI after deploying guestbook:

Argo CD UI after deployment

To check if the application is running or not, we can use the port forwarding command. The service is running on port 80. So, we port-forward the application to 3333 on localhost. When we hit https://localhost:3333, it will show the following UI.

kubectl get svc -n medium
kubectl port-forward svc/guestbook-ui -n medium 3333:80
Application UI

This is all about Argo CD and deploying an application to Argo CD.

Conclusion

This blog walks you through the basics of Argo CD and its benefits. If you want to have a hands-on on the same please refer to this article. This article tells how to install Argo CD, configure Argo CD and Deploy a sample application to minikube. For more understanding of the basics, please refer to the official documentation. https://argo-cd.readthedocs.io/en/stable/

Hope you enjoyed the article and learnt about Argo CD!!

If you liked this article, please consider donating whatever amount you can using this link. It would mean a lot.

--

--

Sharadhi S S

DevOps Engineer with expertise in CI/CD, cloud platform, containerization, and automation Passionate about driving efficient and secure delivery.