ArgoCD GitOps
GitOps continuous delivery for K8s — sync git repo to cluster state.
CI/CDAdvanced
Why
ArgoCD watches a git repo and syncs it to K8s clusters. Git is the source of truth — every change is auditable, and rollback is git revert.
DORA's 2024 State of DevOps report shows elite teams deploy 973x more frequently than low performers. CI/CD pipelines with automated testing reduce change failure rate to 5-15% versus 40-60% for manual deployments.
When
Use ArgoCD for K8s GitOps. Avoid for non-K8s (use Flux for multi-cluster).
How
1. Install — argocd install in cluster
2. App — argocd app create from git repo
3. Sync — auto or manual sync
4. Health — ArgoCD checks app health
5. Rollback — git revert, ArgoCD syncs
6. Multi-cluster — register external clusters
7. App-of-apps — manage many apps
Example
# Install ArgoCD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Create app from git
argocd app create myapp --repo https://github.com/user/k8s-manifests --path apps/myapp --dest-server https://kubernetes.default.svc --dest-namespace default --sync-policy auto
# Application CRD
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: { name: myapp, namespace: argocd }
spec:
source: { repoURL: https://github.com/user/k8s-manifests, path: apps/myapp }
destination: { server: https://kubernetes.default.svc, namespace: default }
syncPolicy: { automated: { prune: true, selfHeal: true } }
Common Problems
- ⚠App out of sync — manual changes in cluster, ArgoCD detects drift
- ⚠Sync fails — manifest error, check ArgoCD UI for sync status
- ⚠Configuration drift between environments — use infrastructure-as-code (Terraform/Pulumi) to keep dev/staging/prod identical
Best Practices
- ✓Use auto-sync with selfHeal — ArgoCD reverts manual changes, git is truth
- ✓Use app-of-apps pattern — one app manages many, hierarchical GitOps
- ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit