Argo CD — A GitOps Tool for Continuous Delivery
ArgoD - GitOps Tool for Continuous Delivery

Argo CD — A GitOps Tool for Continuous Delivery

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
Typical Software Delivery Pipeline

Challenges in this approach are

  • 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.

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 synchronisation of the desired application state with each specified target environment.

No alt text provided for this image

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, 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/stable/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:

No alt text provided for this image
Pods created by argocd

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, 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 get svc -n argocd


kubectl port-forward svc/argocd-server -n argocd 8080:443        
Port-forwarding to access Argo CD UI
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
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
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
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
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/

To get started with more DevOps articles, do follow me on medium: https://medium.com/@raosharadhi11

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

Nilesh Yadav

Aspiring DevOps Engineer | AWS Enthusiast | CI/CD | Kubernetes Explorer | Passionate Learner ??

1 年

Amazing content Sharadhi S.

Papa Moussa FALL

Cloud & DevOps Engineer

1 年

Thanks for sharing

Sven Patrick Meier

Empowering and Mentoring People ?????? Kubernetes (CKAD) ?? GitLab ?? Ansible ??Terraform ?? Cloud-Native ??

1 年

Thank you for sharing this!

Ashabul Elaph Hilful

Site Reliability Engineer | DevOps Engineer |DevSecOps | Ethical Hacker |GCP |AWS |Digital Ocean |CKA |Docker |GitOps |GitLab | Terraform | Ansible | Grafana | Prometheus | RHCSA

1 年

Very useful.Thanks for sharing

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

社区洞察

其他会员也浏览了