Skip to main content
Course/Advanced/GitOps with ArgoCD
6/875 min
Advanced

GitOps with ArgoCD

Automate deployments by treating Git as the single source of truth for your cluster state.

advanced75 minRead β†’ Lab β†’ Quiz β†’ Practice
🧠 Brain Warm-Up
🧠 Brain Warm-Up: If kubectl apply is the way to deploy to Kubernetes, why does running it from a CI/CD pipeline create problems at scale β€” with drift detection, multi-team collaboration, and audit trails? Think about what β€œwho changed what and when” means without a canonical source of truth.

What is GitOps?

GitOps is an operational framework where the desired state of your infrastructure and applications is declared in Git, and an automated agent continuously reconciles the live cluster state toward that declaration.

The four GitOps principles (OpenGitOps):

  1. Declarative β€” desired state described as data (YAML), not scripts
  2. Versioned and immutable β€” Git history is the audit trail; every change is a commit
  3. Pulled automatically β€” an in-cluster agent pulls from Git (no push credentials leave the cluster)
  4. Continuously reconciled β€” the agent detects and corrects drift automatically

GitOps vs Traditional CI/CD

Traditional (Push-based CI/CD)        GitOps (Pull-based)
─────────────────────────────         ────────────────────────────
CI pipeline has kubectl + kubeconfig  Cluster agent pulls from Git
Pipeline pushes changes to cluster    No cluster credentials in CI
Drift is not detected                 Drift auto-corrected every ~3 min
Rollback = re-run pipeline            Rollback = git revert (instant)
Audit trail is CI logs                Audit trail is git history

ArgoCD Architecture

ArgoCD is the most widely-adopted GitOps controller. It runs inside the cluster and watches a Git repository, continuously applying changes.

Git Repository (desired state)
  β”œβ”€β”€ apps/
  β”‚   β”œβ”€β”€ deployment.yaml
  β”‚   β”œβ”€β”€ service.yaml
  β”‚   └── ingress.yaml
  └── config/
      └── configmap.yaml
         β”‚
         β”‚  (ArgoCD polls every 3 minutes or via webhook)
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           ArgoCD Server         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   Application Controller β”‚   β”‚
β”‚  β”‚  (Compares live vs Git)  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚             β”‚ diff detected     β”‚
β”‚             β–Ό                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚    Sync Engine           β”‚   β”‚
β”‚  β”‚  (kubectl apply, Helm    β”‚   β”‚
β”‚  β”‚   template, Kustomize)   β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ applies manifests
               β–Ό
        Kubernetes API Server

ArgoCD Application Resource

The core object in ArgoCD is an Application β€” a CRD that links a Git repo path to a cluster namespace:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd
spec:
  source:
    repoURL: https://github.com/myorg/k8s-manifests
    targetRevision: main
    path: apps/my-app
  destination:
    server: https://kubernetes.default.svc
    namespace: production
  syncPolicy:
    automated:
      prune: true       # delete resources removed from Git
      selfHeal: true    # auto-fix manual drift

Sync Strategies

StrategyBehavior
ManualArgoCD shows OutOfSync but waits for human approval
AutomatedSyncs automatically on every Git change
Automated + selfHealAlso reverts manual kubectl changes that drift from Git
Automated + pruneAlso deletes resources removed from Git

App of Apps Pattern

For managing many applications, ArgoCD supports a hierarchical pattern where one β€œparent” Application manages multiple β€œchild” Applications:

root-app (Application)
  └── apps/ directory in Git
      β”œβ”€β”€ frontend-app.yaml   (Application)
      β”œβ”€β”€ backend-app.yaml    (Application)
      └── monitoring-app.yaml (Application)

This lets you bootstrap an entire cluster's worth of applications with a single ArgoCD Application.