ArgoCD helps to automate the deployment and management of Kubernetes applications using GitOps principles.
In this tutorial, we will learn how to automate the process of deploying and managing the Kubernetes cluster with ArgoCD.
Prerequisites
Minikube local setup
Github account
YAML syntax
Steps
Git repository
Create a GitHub repository and place your Kubernetes configuration files in a directory.
For this demo, we will use a very simple deployment that uses mongodb
and mongo-express
images. All files are available here.
Install ArgoCD in K8s cluster
To install argocd in our K8s cluster, we need to create a namespace called argocd and apply configuration yaml file by using the following commands.
~ kubectl create namespace argocd
~ kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
To access the ArgoCD UI use the following command
kubectl port-forward -n argocd svc/argocd-server 8080:443
Grab the URL and paste it into your browser.
Note:
Username : admin
password is auto-generated and saved in a secret calledargocd-initial-admin-secret
. It can be accessed using the following command and it is in base64 so don't forget to decode it.
kubectl get secret argocd-initial-admin-secret -n argocd
Configure ArgoCD with Application CRD
Let's write a configuration file for argocd to connect it to the git repository where the configuration files are hosted.
YAML File:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: myapp-argo-application
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/Sindhuinti/k8s-configuration/demo.git
targetRevision: HEAD
path: .
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
syncOptions:
- CreateNamespace=true
automated:
selfHeal: true
prune: true
ArgoCD pulls Git repository every 3 minutes. If you don't want this delay, you can configure a Git webhook.
Now apply the configuration file.
kubectl apply -f argocd.yaml
Test our setup by updating configuration files
When you change the configuration files in a Git repository that ArgoCD is monitoring, ArgoCD will detect the changes and initiate a deployment process to update the application in the target Kubernetes cluster.
ArgoCD continuously monitors the Git repository for changes and can automatically synchronize the state of the deployed application with the latest version of the configuration files. When a change is detected, ArgoCD will fetch the new version of the configuration files from the Git repository and generate the appropriate Kubernetes manifests to deploy or update the application.
Congratulations on successfully configuring ArgoCD in your K8s cluster! ๐
I hope you learned something from this blog. If you have, don't forget to drop a like, follow me on Hashnode, and subscribe to my Hashnode newsletter so that you don't miss any future posts. If you have any questions or feedback, feel free to leave a comment below. Thanks for reading and have a great day!