Using ArgoCD for Your GitOps Deployments
Objectives
This tutorial explains how to use ArgoCD, the GitOps continuous deployment tool integrated into your Managed Kubernetes cluster. By the end of this guide, you will know:
- What the GitOps approach is.
- How to access the ArgoCD interface.
- How to deploy an application using ArgoCD to synchronize a Git repository.
The GitOps Principle with ArgoCD
GitOps is a practice that involves using a Git repository as the single source of truth to declare the desired state of your infrastructure and applications.
ArgoCD is the tool that implements this principle. It continuously monitors a Git repository and compares the state defined there (via Kubernetes manifests) with the actual state of your cluster. If it detects a difference, it automatically applies the changes so that the cluster matches what is declared in Git.
The benefits are numerous:
- Reliable and reproducible deployments.
- Complete traceability of all changes via Git history.
- Rapid recovery after an incident by reverting to a previous commit.
- Enhanced security by limiting direct access to the cluster.
Accessing the ArgoCD Interface
The ArgoCD web interface is exposed on an internal URL of your cluster. To access it, you must be connected to the cluster's internal network (for example, via a bastion host or a VPN).
The URL to use is as follows, replacing <votre-identifiant-de-cluster> :
http://argocd.internal.<votre-identifiant-de-cluster>.mk.ms-cloud-temple.com
You can obtain the internal IP address of the ArgoCD Ingress using the following command:
kubectl get ingress argocd-server -n argocd
ℹ️ The password for the
adminaccount is provided by the Cloud Temple teams upon delivery of your cluster.
Deploying an Application with ArgoCD
We will now deploy a test application using the GitOps approach.
1. The Git Repository
ArgoCD requires a Git repository containing the Kubernetes manifests for the application to be deployed. For this tutorial, we will use the ArgoCD example repository: https://github.com/argoproj/argocd-example-apps. We will deploy the guestbook application found in this repository.
2. Prepare the Destination Namespace
For the application to be deployed in a namespace managed by Capsule, we must first create this namespace and apply the appropriate tenant label to it.
Execute the following commands:
# Crée le namespace
kubectl create namespace guestbook
# Applique le label pour l'associer au tenant "default" de Capsule (si besoin, car le namespace a surement déjà été associé avec votre tenant lors de sa création)
kubectl label namespace guestbook capsule.clastix.io/tenant=default
3. Create the application in ArgoCD
Now that the namespace is ready, we can declare the application to ArgoCD.
-
Create a file named
app-guestbook.yamlwith the following content:apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata:name: guestbooknamespace: argocdspec:project: defaultsource:repoURL: https://github.com/argoproj/argocd-example-apps.gittargetRevision: HEADpath: guestbookdestination:server: https://kubernetes.default.svcnamespace: guestbooksyncPolicy:automated:prune: trueselfHeal: trueThis manifest instructs ArgoCD to:
- Create an application named
guestbook. - Monitor the
argocd-example-appsrepository. - Target the
guestbookdirectory in this repository. - Deploy the manifests found in the
guestbooknamespace of the local cluster. - Maintain synchronization automatically (
automated).
- Create an application named
-
You have two options to create the application in ArgoCD:
Option A: Via
kubectl(GitOps Approach)Apply this manifest directly to your cluster. This is the recommended method as it follows the GitOps principle of declarative management.
kubectl apply -f app-guestbook.yamlOption B: Via the ArgoCD web interface
You can also create the application directly from the graphical interface:
- In the ArgoCD UI, click on "+ NEW APP".
- At the top right of the creation screen, click on "EDIT AS YAML".
- Paste the content of your
app-guestbook.yamlfile into the editor. - Click on "CREATE".
4. Verify Synchronization
As soon as you apply the manifest, ArgoCD detects this new Application resource and begins its work.
- Via the web interface:
- Log in to the ArgoCD interface.
- You should see a new card for the
guestbookapplication. - After a few moments, its status should change to
HealthyandSynced. - By clicking on the card, you can view all the Kubernetes resources (Deployment, Service, etc.) that were created.
- Via the command line:
-
Verify that the
guestbooknamespace has been created:kubectl get ns guestbook -
Verify that the application resources are properly deployed in this namespace:
kubectl get all -n guestbookNAME READY STATUS RESTARTS AGEpod/guestbook-ui-85db984648-br6r2 1/1 Running 0 19mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/guestbook-ui ClusterIP 10.111.160.90 <none> 80/TCP 19mNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/guestbook-ui 1/1 1 1 19mNAME DESIRED CURRENT READY AGEreplicaset.apps/guestbook-ui-85db984648 1 1 1 19m
-
5. The GitOps Cycle
Now, if you modify a manifest in the Git repository, ArgoCD will detect the change and automatically update the application in the cluster. That's the magic of GitOps!
Cleanup
To delete the application and all associated resources, you can simply delete the ArgoCD Application resource.
- Via the web interface:
- In the ArgoCD UI, find the
guestbookapplication. - Click the three dots (...) to open the menu and select "Delete".
- Check the "Foreground" option to ensure that all managed resources (pods, services, etc.) are also deleted in cascade.
- In the ArgoCD UI, find the
- Via
kubectl:-
Delete the
app-guestbook.yamlfile you created:kubectl delete -f app-guestbook.yaml
-
ArgoCD will now delete all components of the guestbook application. Once the deletion sync is complete, the guestbook namespace will be empty. You can then delete it using the following command:
kubectl delete namespace guestbook
ℹ️[Going further: secrets management] This tutorial uses a public repository without sensitive data. For your production applications, it is crucial to never store secrets (passwords, API keys) in plain text in your Git repository. >Solutions like Sealed Secrets or OpenTofu integrate with ArgoCD to manage your secrets securely.
Conclusion
You have deployed your first application with ArgoCD following GitOps principles. This powerful approach allows you to manage your deployments in a declarative, reliable, and secure manner. We encourage you to adopt it for all your applications on Managed Kubernetes.