Argo CD and Helm: Deploy Applications the GitOps Way!
Tags: git, argocd, gitops, devops
Published: 2022-12-19 09:01:16

GitOps has become the talk of the town these days. The popularity this approach has gained in the application deployment space is remarkable. Developers find it straightforward to deploy applications using this approach as it removes many bottlenecks. [Argo CD](https://argo-cd.readthedocs.io/en/stable/) & Helm Charts, on the other side, make this GitOps approach easy. Also, with Git being the only source of truth, tracking and observability become easy. Today, we will see how the GitOps approach can be implemented using Argo CD. Using this approach, we will show how to deploy a simple application and Helm charts. 

GitOps works as a modern continuous delivery model where a GitOps agent is used between the Git and target environment (for example, Kubernetes) where our applications get deployed, and it keeps track of all the changes that happen in Git. If there is any change, it pulls the changes to match the expected configuration. The agent compares the actual and desired state. For example, when a developer changes pod numbers in the yaml file from 2 to 4, the agent compares the two states, and when the change gets identified, it pulls the changes to make the two states (actual and desired) even. [Argo CD and Kubernetes](https://harness.io/blog/argo-cd-for-kubernetes) make a great pair when it comes to a well-thought GitOps approach.

## What is Argo CD?
Argo CD is a declarative, GitOps-based continuous delivery tool that helps you deploy applications from Git, manage their lifecycle, and keep your environment in sync. By choosing Argo CD, you can keep your deployments up to date and ensure that your application always follows the desired state. Argo CD allows you to define your applications and their environments as code and then deploy and update them on any Kubernetes cluster.

## What is Helm?
Kubernetes has become the defacto container orchestration tool for modern cloud-native enterprises and it has made the deployment of enterprise applications easier and more efficient. 

But the learning curve involved with Kubernetes is still overwhelming and the it might be a complex tool for some. Understanding Kubernetes requires time. The process of configuring and deploying an application on Kubernetes can be a daunting task. Fortunately, with Helm and Helm Charts, it is now possible to automate the deployment process and quickly deploy and manage applications on Kubernetes. Helm is an open-source tool that helps you manage Kubernetes applications. Helm Charts are packages of pre-configured Kubernetes resources that can be deployed quickly and easily. With the help of Helm and Helm Charts, developers can streamline their Kubernetes deployment process and quickly get their applications up and running. 

## Argo CD vs Helm 
Both are popular open-source tools for managing and deploying cloud-native applications, but they have some major differences. Let's take a look at how they compare with each other. 

- **The first difference** between Argo CD and Helm is the way they deploy applications. Argo CD is a continuous delivery tool/platform that can be used to deploy applications to multiple environments. Whereas Helm is a package manager that can be used to deploy applications to a single environment. Hence, Argo CD is better suited for more complex deployments, and Helm is better suited for simple deployments.

- **The second difference** is the way they manage applications. Argo CD is a GitOps-based tool, which means that it uses Git as a single source of truth and uses it as a focal point to store and track application configurations and manifests. This makes observability very easy and easier to keep track of changes. Even you can roll back to previous versions if needed. Whereas Helm considers Helm charts as a focal point to manage and deploy applications and the changes must be tracked manually.

- **The third difference** is the way they help scale applications. Argo CD is designed to scale horizontally and can easily be deployed to multiple clusters. But with Helm,  you can only deploy to a single cluster. This shows that Argo CD is well suited for large-scale deployments, and Helm is well suited for small-scale deployments.

### Tutorial
For this tutorial, the only pre-requisite is to have access to a Kubernetes cluster. You can also use Minikube or Kind to get a one-node cluster.

First, create a namespace 
`kubectl create namespace argocd`

Apply the manifest file to the namespace created 
`kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml`
![argocd namespace](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2443wxp7r56gtb91cc49.png)

Make sure all your pods are running properly inside the namespace

`kubectl get pods -n argocd`
![argocd pods running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w9qa5fts3ig6u138n3t1.png)

Now, let’s expose our ArgoCD server UI through port forwarding
`kubectl port-forward svc/argocd-server -n argocd 8080:443`

Once you do that, you can now see the ArgoCD UI on https://localhost:8080/
![Argo CD UI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98yofjxf1eaix46c65qy.png)

Now, you need a username and password to log in. By default, the Username is ‘**admin**’ and the password can be generated using the following command,

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

You will get an output as below and use it as your password,
![argo pass](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/brwq2ai9kpq78ihcmw4c.png)

Once you have the username (admin) and the password (zb8EurqNxJkA1eQE), login to ArgoCD

![Argo cd dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9xkzsgnrxwto1zvtyvy.png)

Also, make sure you can use Argo CD locally via CLI, hence install the Argo CD CLI 

`brew install argocd`

Now, you can login and talk to your Argo CD via CLI.

`argocd login localhost:8080`

It will ask you for the username and password. Set both, and the login will be successful.

### Deploying Application via Helm to Argo CD

https://github.com/argoproj/argocd-example-apps is a very successful ArgoCD example repo and will make use of it to deploy a guestbook application via Helm.

**Let’s create an application on ArgoCD**

`argocd app create helm-guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path helm-guestbook --dest-server https://kubernetes.default.svc --dest-namespace default`

You should see the application getting created.
`application 'helm-guestbook' created`

Let’s check the status of the application created,
`argocd app get helm-guestbook`

![argocd app created](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i1u3rt508s7lm2ch1n3z.png)

You can see that both Service and Deployment are in OutOfSync status. Let’s sync the application with the following command,

`argocd app sync helm-guestbook`

![argocd app sync](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zhfxbztxw124ri45fopb.png)

You can now see that the health status of our Service is Healthy and Deployment is Progressing. The Deployment will take some time and becomes Healthy.

You can verify the created application on Argo CD by going to the UI.
![Helm Guestbook](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hlnbhljvxqqfp8jwbhly.png)

Here you can see that the status is _Healthy_ and _Synced_.

By doing the port-forward, you can easily access your deployed application.
`kubectl port-forward svc/helm-guestbook 9090:80` 
![kubectl port forwarding](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j4xdyc1f6tgieco3w6cs.png)

Let’s access our application at http://localhost:9090/

![guestbook application](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rrd8c4du8vu7hgaqejmr.png)

### Deploying Helm Charts with Argo CD
Let us use Argo CD to deploy Helm Charts.

Go to settings in the Argo CD UI and add Repositories.
![Argocd repositories](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lrhksjqsxudvowxj6pq4.png)

Add the following details and connect.
![argocd connect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgs2taky85xjptxa0d2z.png)

You should see your added repository in the list.
![argo helm](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/llws1zry9ri7aktf433k.png)

Now, click on create a new application. We will deploy NGINX Helm chart on Argo CD.

Make sure to specify the required details.
![helm example argocd](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1rxtdbmcpxhsra6c2au2.png)
![argo source](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sp69r6ccjrau92lqzppw.png)

Once you click on create, you should be able to see your application on the Argo CD dashboard.

At first, the application will be out of sync and once we synchronize the application, it gets synced and shows healthy.
![helm status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u93ihm8lxnkc5hp9fd8k.png)

Click on ‘Sync’ and then ‘Synchronize’
![argo cd sync cancel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yip88qh63zye23s4b1c0.png)

Now, if you go back and see, your application should show Healthy and Synced status. 
![Helm healthy status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1nkzdg7ukhhw81ts67g2.png)

### GitOps Using Harness
Harness provides native GitOps functionality that lets you deploy services by syncing the Kubernetes manifests in your source repos with your target clusters. First, you set up Harness GitOps by installing a GitOps Agent in your environment. Next, you define how to manage the desired and target state in a GitOps Application in Harness. The GitOps Agent performs the sync operations defined in the Application and reacts to events in the source and target states.
![Harness GitOps](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zomkhpkupwn3i4trtdfw.png)

You will need to sign up for a [Free Harness Account](https://app.harness.io/auth/#/signup/?module=cd&?utm_source=website&utm_medium=harness-developer-hub&utm_campaign=cd-plg&utm_content=get-started) and navigate to the GitOps tab.

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

You can follow this simple [Harness GitOps tutorial](https://developer.harness.io/tutorials/deploy-services/helm-argocd-gitops-k8s/?utm_source=internal&utm_medium=social&utm_campaign=community&utm_content=pavan-gitops-article&utm_term=gitops) to see how intuitive and simple it is to deploy applications via [Harness GitOps](https://docs.harness.io/article/w1vg9l1j7q-harness-git-ops-basics?utm_source=internal&utm_medium=social&utm_campaign=community&utm_content=pavans-gitops-article&utm_term=gitops).