- Published on
GitOps: ArgoCD Basics
- Authors
- Name
- Ruan Bekker
- @ruanbekker
In our previous post we went through GitOps Fundamentals, and why its a thing. In this post we will go through the basics of ArgoCD and see how powerful it is in the world of GitOps.
Introduction to ArgoCD
ArgoCD implements GitOps best practices in the following methods:
- In order to use ArgoCD, it gets deployed on the cluster that you want to manage.
- You then store your manifests in Git (such as: Kubernetes manifests, Helm Charts, Kustomize manfests, etc.)
- You define a ArgoCD application and you point it to the Git repo which hosts your manifests and then it continuously monitor the repository for changes.
- Whenever these manifests changes in Git, it will sync the changes down to the cluster.
- You also have options where it can automatically fix configuration drift.
Installing ArgoCD
There are a couple of ways to deploy ArgoCD, where using kubectl
is probably the easiest to do:
kubectl create ns argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
The method that I personally prefer is using Helm, as then we can let ArgoCD manage itself:
helm upgrade --install argocd oci://ghcr.io/argoproj/argo-helm/argo-cd --version 7.7.22 --namespace argocd
And for Production setups, you can have a look at Autopilot:
Accessing ArgoCD
Once your deployment has completed you can retrieve the admin password using:
kubectl get secret argocd-initial-admin-secret -n argocd \
-o jsonpath="{.data.password}" | base64 -d
And to run a local port-forward to access ArgoCD on port 8080:
kubectl -n argocd port-forward svc/argocd-server 8080:80
Creating Applications on ArgoCD
You have 3 options on how to create applications on ArgoCD:
- Create the application via the Web Interface
- Create the application via the CLI
- Create the application by defining it declaratively in Git (best way).
Creating Applications via the WebUI
To create applications via the WebUI, you create a new application and then theres a wizard that asks you for (app name, project, sync policy, repository url, path, branch etc.)
Creating Applications via the CLI
You need to download the cli tool from their github releases page, and then reference the documentation on how to authenticate. Once that is done a sample application can be created like this.
Note, this example points to a helm chart, but it can point to a ArgoCD Application, Kubernetes manifests or Helm charts.
argocd app create sample-app \
--project default \
--repo https://github.com/ruanbekker/argocd-examples \
--path ./apps/hello-world --dest-namespace argocd \
--dest-server https://kubernetes.default.svc
Creating Applications Declaratively
You can define the application in yaml, and then either deploy it via kubectl, or better, you define it inside a Git repository. A Application would look like this:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: demo-app1
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: https://github.com/ruanbekker/argocd-examples.git
targetRevision: HEAD
path: ./apps/hello-world
destination:
server: https://kubernetes.default.svc
namespace: demo1
syncPolicy:
syncOptions:
- CreateNamespace=true
automated:
prune: true # Also delete resources if they are deleted in Git.
selfHeal: true # Helps with drift, it will revert manual changes.
Synchronization with ArgoCD
Once the application was created, ArgoCD will keep monitoring the Git repo for changes (every 3 minutes), and once a change is picked up, it will automatically sync the changes to the cluster (if automated sync is enabled).
You can however select the sync button manually if you want to force it.
If you have automated sync disabled, you can select "Refresh" and then it will give you the desired vs actual state changes in the "diff" section, which is quite nice:
You can also sync applications using the cli using:
argocd app sync sample-app
And using kubectl
you should be able to view the application using:
kubectl -n argocd get application/sample-app
Up Next
Thats it for the ArgoCD Basics, in the next post we will go through handling secrets in our deployments, deployment with Helm and Kustomize and going a bit deeper in syncing strategies and declarative setups.
You can follow all the posts using the tag #gitops
Thank You
Thanks for reading, if you like my content, feel free to check out my website, and subscribe to my newsletter or follow me at @ruanbekker on Twitter.
- Linktree: https://go.ruan.dev/links
- Patreon: https://go.ruan.dev/patreon