4 Hours

5. Argo CD & GitOps: Kubernetes Continuous Deployment

GitOps

GitOps is a paradigm for continuous deployment where Git is the single source of truth for infrastructure and application configuration. Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes. Understanding GitOps and Argo CD is essential for modern cloud-native CI/CD.

The key insight is that GitOps uses Git as the source of truth for both code and infrastructure. Changes are made by updating Git, and the system automatically reconciles the live state with the desired state. This provides auditability, rollback, and consistency. Argo CD continuously monitors your Git repository and Kubernetes cluster, automatically applying changes.

This module covers GitOps principles, Argo CD architecture, application deployment, sync policies, and best practices.

GitOps Principles

GitOps is built on four core principles: Declarative Configuration (everything is defined in YAML), Version Control (Git is the single source of truth), Automated Reconciliation (the system continuously ensures the live state matches the desired state), and Observability (visibility into deployment status). These principles enable reliable, auditable, and self-healing deployments.

GitOps provides several benefits: faster recovery (rollback is just a Git revert), developer experience (developers use familiar Git workflows), security (no direct access to clusters), and consistency (all environments are declared in Git). Understanding these principles is essential for implementing GitOps effectively.

  • Declarative Configuration: All infrastructure defined as code in Git.
  • Version Control: Git is the single source of truth.
  • Automated Reconciliation: System continuously applies desired state.
  • Observability: Visibility into deployment status and drift.

Argo CD Architecture

Argo CD is a Kubernetes controller that continuously monitors Git repositories and Kubernetes clusters. It compares the desired state (in Git) with the live state (in the cluster). If they diverge, it automatically reconciles them. Argo CD supports multiple environments (staging, production, etc.) and can sync with multiple Git repositories.

Argo CD consists of the API Server, Repository Server, Application Controller, and Dex (for SSO). The API Server provides the UI and API. The Repository Server caches Git repositories. The Application Controller monitors applications and reconciles state. Understanding this architecture is essential for deploying Argo CD effectively.

Step-by-Step: Argo CD Deployment

Follow these steps to deploy an application with Argo CD.

Step 1: Install Argo CD
kubectl create namespace argocd<br>kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

Step 2: Access the UI
kubectl port-forward svc/argocd-server -n argocd 8080:443
Open https://localhost:8080

Step 3: Create an application
Create an Application YAML file:
apiVersion: argoproj.io/v1alpha1<br>kind: Application<br>metadata:<br> name: my-app<br> namespace: argocd<br>spec:<br> project: default<br> source:<br> repoURL: https://github.com/your-username/app-repo.git<br> targetRevision: HEAD<br> path: k8s/<br> destination:<br> server: https://kubernetes.default.svc<br> namespace: my-app<br> syncPolicy:<br> automated:<br> prune: true<br> selfHeal: true

Step 4: Apply the application
kubectl apply -f application.yaml

Step 5: View the application
In the Argo CD UI, you'll see your application synced and healthy.

Try It Yourself: Create a Git repository with Kubernetes manifests. Configure Argo CD to automatically sync changes from Git to the cluster. Add a webhook to trigger sync on Git push.

Knowledge Check

Ready to test your understanding of 5. Argo CD & GitOps: Kubernetes Continuous Deployment?

Back