Streamlining CI/CD in Kubernetes Using Argo CD: A Comprehensive Guide

As organizations increasingly adopt cloud-native technologies, one of the critical components in ensuring application scalability and performance is setting up efficient continuous integration/continuous delivery (CI/CD) pipelines. Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes, enabling you to manage application deployments automatically. In this blog post, we’ll take a detailed look at how to set up a CI/CD pipeline using Argo CD, complete with step-by-step instructions and example scripts.

Why Argo CD?

Argo CD offers several compelling features:

  • Declarative Setup: Your entire deployment configuration is stored as code in a Git repository, enabling version control and easier rollbacks.
  • Automated Deployment: Argo CD automatically syncs your Kubernetes applications whenever changes are detected in the Git repository.
  • Visibility and Control: Provides a web-based UI for monitoring application states and manually overriding deployments if required.
  • Scalability: Efficiently manages multiple clusters and high numbers of applications.

Prerequisites

  • A Kubernetes cluster
  • kubectl installed and configured
  • GitHub account for storing the Git repository

Step-by-Step Guide to Setting Up Argo CD

Step 1: Install Argo CD

Start by installing Argo CD in your Kubernetes cluster.

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

Step 2: Access Argo CD UI

Argo CD API server, by default, is not exposed with a LoadBalancer. To expose the Argo CD API server, run:

kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'

Obtain the initial admin password for Argo CD:

kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo

Access the Argo CD web UI by opening your browser to the Argo CD server’s IP address. Log in with the username admin and the password you obtained.

Step 3: Create a Git Repository for Your Kubernetes Manifests

Initialize a Git repository to store your Kubernetes manifests. Here’s an example directory structure:

my-gitops-repo/
├── kustomization.yaml
├── namespace.yaml
└── deployment.yaml

Commit and push these files to your GitHub repository.

Step 4: Define Your Kubernetes Manifests

namespace.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: my-app

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  namespace: my-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: my-app:latest
          ports:
            - containerPort: 8080

kustomization.yaml

resources:
  - namespace.yaml
  - deployment.yaml

Step 5: Connect Argo CD to Your GitHub Repository

Create a new application in Argo CD to connect to your GitHub repository:

argocd app create my-app \
  --repo https://github.com/yourusername/my-gitops-repo.git \
  --path ./ \
  --dest-server https://kubernetes.default.svc \
  --dest-namespace my-app

Synchronize the application:

argocd app sync my-app

Verifying the Setup

After synchronization, check the status of your application in the Argo CD dashboard. It should show all resources as up-to-date and healthy.

Lessons Learned

  • Ease of Setup: Argo CD’s declarative approach simplifies the complex process of continuous deployment.
  • Enhanced Visibility: The web UI provides a clear view of application states and deployment history.
  • Improved Collaboration: Storing configurations in Git allows for better collaboration and version control.
  • Scalability: Argo CD efficiently manages large-scale applications across multiple clusters.

Conclusion

Argo CD is a powerful tool for managing continuous delivery in Kubernetes environments. By following the steps outlined in this guide, you can set up a robust CI/CD pipeline that automates deployments, increases visibility, and ensures consistency. If you have tried Argo CD or have any questions, feel free to share your experiences and insights in the comments below!