Continuous Delivery with Argo CD and Kubernetes
Overview
Continuous Delivery (CD) has become a cornerstone practice for organizations striving to deliver high-quality software at scale, efficiently and reliably. Among the myriad of tools available to facilitate CD, Argo CD stands out as a powerful and flexible solution for managing Kubernetes applications.
Argo CD
Argo CD is an open-source, declarative continuous delivery tool designed to automate the deployment of applications to Kubernetes clusters. It provides a GitOps-driven approach, where the desired state of your applications is defined in Git repositories, and Argo CD ensures that the actual state matches the desired state, continuously reconciling any discrepancies.
Some of the Important features of Argo CD are as follows:
- Declarative Configuration: Argo CD uses declarative YAML manifests to define the desired state of applications and their environments, making it easy to version control and manage changes.
- GitOps Workflow: With Argo CD, the entire application deployment process is driven by Git repositories, enabling GitOps principles such as versioning, auditing, and rollback.
- Automated Syncing: Argo CD continuously monitors the Git repositories for changes to the application manifests and automatically syncs the clusters to ensure that the actual state matches the desired state.
- Multi-Environment Support: It supports managing multiple environments (e.g., development, staging, production) with different configurations and access controls, allowing for consistent and reliable deployments across environments.
- Customizable Rollback: In case of failures or issues during deployment, Argo CD provides seamless rollback capabilities, allowing you to revert to previous known-good states with minimal downtime.
In this blog post we will try to deploy an application onto our Kubernetes Cluster using Argo CD
Demo
Pre-requisites
Existing Kubernetes cluster
You can either create your cluster on the cloud using tools like AWS EKS or setup a local minikube cluster
For setting up a Kuberentes cluster on EKS, please refer to my previous blogpost:
For minikube installation:
Existing Docker image
Any pre-configured docker image can be used for this demo. In the below example, I am using an image which i have published on docker hub prashantdocker87/eks-demo:1.0
It is a simple spring boot application with some REST endpoints
Source code
The source code consists of a sample argo cd project with Argo CD artifact and couple of Kubernetes artifacts.
The Argo CD artifact will be used to define the Argo CD configurations whereas the Kubernetes artifacts will be deployed on the Kuberentes cluster using Argo CD.
Installation
Step-01: Install Argo CD on your Kubernetes Cluster
# Install Argo CD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Get List of components installed
kubectl get all -n argocd
kubectl -n argocd get pods
You should wait for all the pods to be in ready state.
Step-02: Deploy Argo CD configuration
This step will setup the configuration for Argo CD .
kubectl -n argocd apply -f application.yaml
The application.yaml consists of the following contents:
apiVersion: argoproj.io/v1alpha1 |
kind: Application |
metadata: |
name: eks-demo-argo-application |
namespace: argocd |
spec: |
project: default |
source: |
repoURL: https://github.com/prashant-hariharan/eks-argocd.git |
targetRevision: HEAD |
path: dev |
destination: |
server: https://kubernetes.default.svc |
namespace: myapp |
syncPolicy: |
syncOptions: |
- CreateNamespace=true |
automated: |
# The automated sync will create a new revision of the application when changes are detected. |
# If we apply changes to cluster manually using kubectl, argocd will override it with self heal |
selfHeal: true |
prune: true |
The application.yaml defines the source -> the kubernetes artifacts and the destination->Kubernetes cluster for the ARGO CD.
This basically means that ARGO CD monitors the git hub repo and as soon as it identifies any changes in the repo, it will sync the artifacts in the kubernetes cluster.
Additionally, we have also defined in the yaml, that Argo CD should create a new namespace myapp where the kuberentes artifacts will be deployed.
These options are defined by using the syncPolicy option in the yaml file.
Step-03: Argo CD UI
Argo CD also provides a UI which can be used to visualize the status of the cluster.
To View the UI you need to perform the following steps:
Enabling port forwarding to access the UI
kubectl port-forward svc/argocd-server 8080:443 -n argocd
The above command will enable you to access the ui on localost:8080 by port forwarding the request to the Argo CD server.
Credentials
The Argo CD UI needs the following login credentials:
username: admin
The password can be retrieved from your kubernetes cluster using the following command:
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
Step-04: Application Access
The application is exposed as a service. By getting the DNS name of the service, you can the application using:
<DNS>/swagger-ui.html
To get the DNS name, just run the following command
kubectl -n myapp get svc
Step-05: Tear Down
You can delete the Argo CD application by removing the application from UI.
References
Tutorials: https://www.youtube.com/watch?v=MeU5_k9ssrs
Prashant Hariharan is an AWS certified Architect as well as a Java Team Lead at MATHEMA GmbH. He specializes in Architecting and Developing Enterprise as well as cloud based applications.