Argo CD

Tags: git, gitops, sre
Published: 2020-12-27 20:23:44

Originally published on [mccricardo.com](https://mccricardo.com/gitops-argocd/).

There are several options when it comes to Continuous Delivery, powered by the GitOps toolkit, and [Argo CD](https://argoproj.github.io/argo-cd/) is one of the most popular. It describes itself as "a declarative, GitOps continuous delivery tool for Kubernetes."

Following the GitOps philosophy, Argo is/has:
  - **declarative** since it uses Git as its source of truth where the entire desired state is described;
  - **automated** because it can read state (described in YAML) and act upon it;
  - **auditable** due to Git history;
  - **designed for Kubernetes** from the ground up;
  - **out-of-the-box integrations** so that the wheel doesn't need to be reinvented;
  - **extensible** allowing for particular use cases to be added.

## Get the ball rolling

We will be spinning a local Kubernetes cluster with [k3d](https://k3d.io/) and deploying a demo [Guestbook application](https://github.com/argoproj/argocd-example-apps/tree/master/helm-guestbook) described in [Helm](https://helm.sh/) and will let Argo take care of deploying it. We need the following tools to make this happen:
  - [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
  - [k3d](https://k3d.io/)
  - [argocd](https://github.com/argoproj/argo-cd/releases/tag/v1.8.1)

We start by creating a local Kubernetes cluster with [k3d](https://k3d.io/):
```sh
k3d cluster create -a 2 gitops
k3d kubeconfig merge gitops --switch-context
```

We then create a namespace for Argo and deploy it:
```sh
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
```

A password is auto generated. We will retrieve it and login in with the cli and the web interface:
```sh
# Retrieve password
kubectl get pods -n argocd -l app.kubernetes.io/name=argocd-server -o name | cut -d'/' -f 2

# cli login
argocd login localhost:8080

# Update password, if you prefer
argocd account update-password

# Port-forward to access the UI
kubectl -n argocd port-forward svc/argocd-server  8080:443
```

The next few steps can be done in the UI or the command line. The UI will be left for the reader to explore and we'll use the command line. We will create the application in Argo and point to the Helm charts:
```sh
argocd app create guestbook \
    --repo https://github.com/argoproj/argocd-example-apps.git \
    --path helm-guestbook \
    --dest-server https://kubernetes.default.svc \
    --dest-namespace default
```

We can check the status of the application in the command line or the UI:
```sh
argocd app get guestbook
```
![](out-of-sync.png)

`OutOfSync` is the initial application status because the application has yet to be deployed, all Kubernetes resources have to be created. We'll sync it by running:
```sh
argocd app sync guestbook
```

![](synced.png)
![](details.png)

After Argo has done it's magic we can, at last, access the application:
```sh
kubectl port-forward svc/guestbook-helm-guestbook  9090:80
```

We've barely scratched the surface of what Argo can do but, with only a bit code we were able to deploy an application effortlessly. Argo is very powerful and can do a lot more and, in case you're interested, take a look a the [documentation](https://argoproj.github.io/argo-cd/).