Continuous Delivery with ArgoCd
Argo Cd is one of the most popular declarative , gitops Continuous Delivery tools present for kubernetes. We are going to check out how you can leverage ArgoCd to continuously deploy your work loads and follow gitOps based approach to deploy your kubernetes resources.
For this demo we are going to be using minikube cluster , but the steps given here can well be applied to any cluster of your choice.
For reference you can check this github repository which will contains all the files here in this link.
Start your minikube cluster using the command minikube start
Under the repository the folders are divided as specified
yamls -> all the kubernetes resources we wish to deploy
installs -> all the yamls for setting up argocd in our cluster , these have been taken from the official argocd repositories
config -> custom resource definitions to be used by a user to setup argocd pipelines
We will be dividing our entire task into 3 steps
Step 1: Setup argocd in our cluster
Create a namespace argo to keep all our argocd resources under that namespace
kubectl create namespace argocd
Apply all the argocd resources using the command kubectl apply -n argo -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
This file is present in installs/argocd.yaml
This will create all the custom resources required by argocd in the argo namespace.
Step 2 : Deploy custom resources of argocd
If you check your argocd namespace you should see a bunch of resources created , the argocd-server is the once with which we will be interacting directly
Check your namespaces using kubectl get all -n argocd
ArgoCd also provides a nice UI to check your builds and configuration , this UI can be accessed by port forwarding the argocd-server service in the argocd namespace.
kubectl -n argocd port-forward svc/argocd-server 8085:80 , to run it in background attach & ,here I have port forwarded to the 8085 port
The default credentials are present in a secret argocd-initial-admin-secret
Get the secret using the command kubectl get secret argocd-initial-admin-secret -n argocd -o yaml
In the yaml under the data part the secret is present base 64 encoded , decode it and use it for the password field (username admin)
Use the password obtained and username admin to login to your server
Currently we do not have any projects or applications attached so , that is what we are going to configure next.
Projects allow us to group together applications , setup restrictions , destination of deployment etc. We are going to configure a project for our GitHub repository for a development environment.
This specifies a project to be created with the required rules , currently I have provided permission for all namespaces. The server block specifies which kubernetes cluster , I have chosen the default one (minikube) this can be checked from the UI under settings/clusters
Once you apply head over to projects in your argo UI and a new project will be configured.
Now we will create an application which will reference to that project and also contain the github repository and path for the yamls.
The following yaml specifies my application , source specifies the github repository URL along with path for my yaml files and target Revision.
The destination specifies which cluster I would like to deploy and namespace .
SyncPolicy is added so that argocd can detect changes in the github repository and automatically deploy those changes.
The project which we created before is referenced under spec.
Head over to applications and you can see your new application.
Step 3 : Deploy the application
Since we have automated the sync policy our files are being automatically deployed
You can remove the auto sync and deploy manually too.Our cluster state previously was this
We now have a pod, deployment , service and ingress present in our cluster.
Also our ingress is working
If we remove everything and remove auto deploy we can deploy manually too
You will get a message of out of sync .
Click on sync to sync your changes
Our resources should be deployed again
This way we can leverage argocd to define the state of our cluster that we desire and argocd can manage the cluster state without the interference of any external developer.
You can check more about kubernetes in this repository here https://github.com/DiptoChakrabarty/Kubeadmin
If you like the blog and would like to know more please leave a clap or comment below.