Drift and Reconciliation
What configuration drift is, how GitOps agents detect OutOfSync resources, and how automated reconciliation heals the cluster.
TL;DR
Drift happens when live cluster state diverges from Git—usually from a manual kubectl edit. A GitOps agent continuously compares live objects against Git, flags OutOfSync, and with self-heal enabled automatically reconciles the cluster back to Git.
Intent
Understand how GitOps agents detect configuration drift and reconcile live clusters back to Git—and why manual hotfixes get overwritten unless they go through Git.
Problem
During an outage, someone runs kubectl edit deployment web to bump replicas or change an environment variable, fixes the fire, and forgets to update Git. Weeks later, the next deployment silently wipes out that hotfix—or worse, nobody knows why production behaves differently from staging.
Solution
GitOps treats reconciliation as a continuous control loop rather than a one-time deploy script:
- Observe: The GitOps agent (Argo CD or Flux) watches live Kubernetes resources via the API Server and compares them against the rendered manifests from Git.
- Detect Drift: Any difference in tracked fields (replicas, image tag, env vars) marks the application OutOfSync.
- Reconcile (Self-Heal): With automated reconciliation enabled (
selfHeal: truein Argo CD, or default periodic interval in Flux), the agent reapplies the Git manifests tokube-apiserver, overwriting the manual edit. - Prune (optional): If
prune: trueis set, resources deleted from Git are also deleted from the cluster.
Real-world analogy
▶ Flow: watch it work
Drift & Reconciliation: Manual Edit → OutOfSync → Self-Heal
Press Start or tap any step dot to trace the path.
▸All steps (6)
Code
Comparing Flux (Kustomization) and Argo CD (syncPolicy) reconciliation settings:
# Flux Kustomization reconciles drift automatically on its interval (not run)
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: web-app
namespace: flux-system
spec:
interval: 5m
path: ./apps/web
prune: true
sourceRef:
kind: GitRepository
name: k8s-configWhen to use / when to avoid
- You want production clusters to stay strictly aligned with Git and reject undocumented manual edits.
- You need alerts when a cluster goes OutOfSync even if auto-heal is turned off.
- Do not enable automated prune: true on stateful databases or namespaces until you test deletion protection.
- Do not fight the agent during an incident—pause auto-sync explicitly if you must hotfix live, then commit the fix to Git.
How to implement
Start with drift detection only
Enable GitOps sync notifications so you see OutOfSync diffs before turning on selfHeal.
Enable self-heal for stateless workloads
Turn on selfHeal: true (Argo CD) or rely on Flux's reconciliation interval so drift heals automatically.
Handle HPA and mutated fields cleanly
Configure ignoreDifferences for fields mutated at runtime (such as spec.replicas when using a HorizontalPodAutoscaler).
Pros / Cons
- Eliminates "snowflake" clusters where production silently diverges from staging.
- Makes cluster rebuilds repeatable because everything live is already in Git.
- Runtime-mutated fields (like HPA replica counts) can cause false OutOfSync noise if not ignored.
- Enabling prune: true without care can delete resources removed from Git.
Relations
Check yourself
Check Yourself
1. An operator runs kubectl scale deployment/web --replicas=5 on a cluster where Git specifies replicas: 3 and Argo CD has selfHeal: true. What happens?
2. Why might an application show OutOfSync even when no human ran kubectl edit?
Sources
Related Notes
What Is GitOps? (Pull vs Push)
How GitOps uses a declarative Git repository as the single source of truth and an in-cluster pull agent to converge cluster state.
Argo CD vs Flux: Picking a GitOps Controller
Compare Argo CD and Flux CD across architecture, web UI, multi-tenancy, Helm/Kustomize support, and team fit.