Introducing ArgoCD: A GitOps Approach to Continuous Deployment
Tags: gitops, argocd, docker, kubernetes
Published: 2024-02-04 08:40:33

## What is a CI/CD pipeline? 🔄

A **CI/CD** (_Continuous Integration/Continuous Deployment_) pipeline automates software delivery processes, ensuring frequent code integrations, tests, and deployment. It starts with Continuous Integration, merging code changes regularly, followed by Continuous Deployment, automating the release to production, enabling faster, more reliable software delivery.


![CI/CD pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnqhy4grg1vpojqtdywh.png)

## Why do we need to decouple CD pipeline from CI pipeline? 🤔

Decoupling **CD** from **CI** enhances flexibility in software release cycles. It allows independent scaling, optimizations, and customization of deployment processes. This separation prevents bottlenecks, enabling tailored strategies for testing, deployment, and release, fostering a more efficient and adaptable development workflow.

## What is GitOps? 

GitOps is a DevOps methodology where the entire system state is declared and managed in a Git repository. Automation tools use **Git as the single source of truth** to continuously deploy and update infrastructure and applications.


![GitOps](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xiwjxpuc0pyazm66dn9i.png)

## What is ArgoCD ❓

ArgoCD is an open-source Continuous Delivery tool used for deploying and managing applications in Kubernetes clusters. It utilizes a GitOps approach, syncing the desired application state defined in Git repositories with the actual state in the cluster, ensuring consistency and enabling automated deployments and updates.



![ArgoCD](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1gns5h4v3oysu31nd3f.png)

## Advantages of using GitOps with ArgoCD 🌟

1. **Enhanced Collaboration:** Facilitates team collaboration by using Git as a single source of truth, enabling code reviews, versioning, and collaboration among team members. 👥
2. **Auditability and Rollbacks:** Offers a transparent audit trail of changes, allowing easy rollbacks to previously known working states by reverting changes in the Git repository. 🔍
3. **Scalability and Efficiency:** Scales well for complex applications, enabling efficient management of multiple environments and configurations with minimal human intervention. 🚀

## How does ArgoCD Work? 🤔

Let's understand it through a diagram.


![ArgoCD works](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxx6wveco1gxp5gua5p6.png)

Now, a step-by-step breakdown of how ArgoCD works from code commit to deployment on k8s:

- Developers send source code to the Source Code Repo; then, the CI pipeline tool updates the deployment configuration in the GitOps Repo.
- The DevOps team can also commit Deployment Manifests to the GitOps Repo.
- ArgoCD is configured to watch a specific Git repository and branch where the code changes are stored.
- ArgoCD continuously monitors the designated Git repository for changes **Through a Pull-Based Model.**
- When developers push changes, ArgoCD detects the modifications in the Git repository.
- ArgoCD compares the code changes in the Git repository (desired state) with the current state of applications in the Kubernetes cluster.
- If there are disparities between the desired and current states, ArgoCD initiates a synchronization process.
- ArgoCD automates the deployment process based on code changes, updating the Kubernetes cluster to match the desired state.
- After deployment, ArgoCD verifies that the changes meet specified criteria. In the event of issues, ArgoCD seamlessly performs automated rollbacks, reverting to the previous known stable state for a reliable and consistent application environment.
- ArgoCD continues to monitor the Git repository for new changes, repeating the process to maintain a continuous deployment cycle.

## Installation of ArgoCD in K8S Cluster 🛠️

**Prerequisites:**

- Any k8s cluster
- Docker Engine
- Kubectl
- Helm
- Github Account
- Dockerhub Account

**Install ArgoCD:**

```bash
kubectl create namespace argocd
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm install argocd argo/argo-cd --namespace argocd
```

**Access ArgoCD UI on Port 8080:**

```bash
kubectl port-forward svc/argocd-server -n argocd 8080:443
```

**The Login UI will look like the image below:** We have to provide the Username and Password.


![Login UI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ga2j0z1sxua9tdpey1o9.png)

The initial _Username_ is **admin**

To get the _password_, run this command:

```bash
kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 --decode
```

**In our upcoming blog, we'll dive into deploying an application using ArgoCD. Until then, take care and have a fantastic day ahead!** 🎉🌈