GitOps
Try it
Ship, drift, revert- a1f3c2eshop: deploy v1HEAD
replicas: 4
image: shop:v1- argoApplication shop is Synced and Healthy
Try kubectl scale in prod with selfHeal on, then again with it off. With selfHeal off, the drift stays until someone syncs.
The four principles
From the CNCF OpenGitOps projectDeclarative
You describe the state you want, not the commands to get there.
Versioned and immutable
Desired state lives in Git, with full history. Every change is a commit you can review, audit and revert.
Pulled automatically
An agent in the environment fetches the desired state. Nothing outside pushes into it.
Continuously reconciled
The agent keeps comparing live state with desired state and corrects any drift.
Push vs pull
| Push (classic CI/CD) | Pull (GitOps) | |
|---|---|---|
| Who changes the cluster | CI pipeline runs kubectl or helm | An agent inside the cluster (Argo CD, Flux) |
| Cluster credentials | Stored in CI, outside the cluster | Stay inside the cluster |
| Drift (manual edits) | Unnoticed until the next deploy | Detected, and undone if selfHeal is on |
| Rollback | Re-run an old pipeline | git revert |
| Audit trail | Pipeline logs | Git history and pull request reviews |
| Many clusters | One pipeline step per cluster | Each cluster pulls for itself (ApplicationSets) |
How it fits together
A common setup uses two repositories. The app repo holds code, and its CI builds and pushes an image. The config repo holds the Kubernetes manifests. CI's last step is a commit that bumps the image tag. CI never needs cluster credentials.
Argo CD watches the config repo and syncs. If the manifest is an Argo Rollouts Rollout, the sync starts a canary or blue-green rollout. GitOps decides what should run, and the rollout strategy decides how it gets there.
Across many clusters, an ApplicationSet generates one Application per cluster. With progressive syncs it can roll out ring by ring.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: shop
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/example/shop-deploy
targetRevision: main
path: k8s/overlays/production
destination:
server: https://kubernetes.default.svc
namespace: shop
syncPolicy:
automated:
prune: true # delete what was removed from Git
selfHeal: true # undo manual changes in the cluster
syncOptions:
- CreateNamespace=true