GitOps with ArgoCD
Automate deployments by treating Git as the single source of truth for your cluster state.
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):
- Declarative β desired state described as data (YAML), not scripts
- Versioned and immutable β Git history is the audit trail; every change is a commit
- Pulled automatically β an in-cluster agent pulls from Git (no push credentials leave the cluster)
- 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 ServerArgoCD 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 driftSync Strategies
| Strategy | Behavior |
|---|---|
| Manual | ArgoCD shows OutOfSync but waits for human approval |
| Automated | Syncs automatically on every Git change |
| Automated + selfHeal | Also reverts manual kubectl changes that drift from Git |
| Automated + prune | Also 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.