Every team that adopts GitOps starts with the same promise: Git is the single source of truth, and the cluster will always reflect it. In my experience, that promise holds for the first few weeks. Then someone runs kubectl edit during an incident at 2 AM, a HorizontalPodAutoscaler mutates replicas, or a Helm hook leaves a stray Job behind. The next morning, Git says one thing and the live cluster says another. That divergence is drift, and how you detect and reconcile it determines whether GitOps actually gives you reliability or just the illusion of it. I've spent the last three years operating GitOps at scale across multiple clusters and two different toolchains, and the difference between teams that sleep well and teams that don't is rarely the choice of tool — it's how deliberately they design their reconciliation contract.
This article covers the mechanics of drift detection and reconciliation as they work in real production Kubernetes environments. We'll look at where drift comes from, how controllers like ArgoCD and Flux compare live state to desired state, how to tune reconciliation loops without thrashing your API server, and when you should explicitly choose not to reconcile. If you are running GitOps beyond a single dev cluster, these are the controls that keep your declared state honest.
The Silent Divergence: Why Manual Patches Break Git's Authority
The core value of GitOps is not that you store YAML in Git. It's that you can reason about the cluster by reading Git alone. Drift breaks that reasoning. When live state diverges from Git, rollbacks become unreliable, audits fail, and the next sync can produce surprising results because the controller is reconciling against a state you no longer understand.
In my experience, the most dangerous drift is not the obvious kind where someone changed an image tag. It's the subtle field-level drift that accumulates in annotations, labels, and defaulted fields. A common example is a Deployment where Git declares replicas: 3 but an HPA has scaled it to 6 during load. If your diff tool does not understand field ownership, every reconciliation loop will show as OutOfSync, generating noise that hides real problems. Worse, if you have self-healing enabled without exclusions, the controller will fight the HPA and scale back to 3 every few minutes.
How Kubernetes Tracks Desired vs Live State
Kubernetes itself does not natively store a Git reference. It stores three representations that GitOps controllers must reconcile: the desired state from Git, the live state from etcd, and the last-applied configuration. Before server-side apply, controllers relied on kubectl.kubernetes.io/last-applied-configuration. Now, with Kubernetes Documentation on server-side apply, the API server tracks managedFields per controller. This matters because a naive kubectl diff will flag fields that the API server defaulted — like resources.limits or service.spec.clusterIP — as drift when they are not. According to the Kubernetes Documentation, defaulting and mutation happen via admission controllers before persistence, so your reconciliation logic must account for what the API server will actually store, not just what you wrote in Git.
The practical consequence: if you build custom drift detection scripts that do a simple yq compare between Git and kubectl get -o yaml, you will drown in false positives. Production-grade controllers handle this by performing a three-way diff that understands which fields are owned by which manager and which fields are safe to ignore.
Classifying Drift Sources: Humans, Autoscalers and Controller Fights
I've found that categorizing drift by its source makes it much easier to decide how to handle it. Not all drift should be reverted automatically.
1. Human-initiated drift. This is kubectl scale, kubectl edit, or manual changes made via dashboards during incidents. It is the most common source in teams new to GitOps. Without detection, these edits become permanent because the next person assumes Git is accurate.
2. System-initiated drift. This includes autoscalers (HPA, VPA, Karpenter), operators that mutate resources (Istio sidecar injection, cert-manager adding annotations), and Kubernetes itself (defaulting, garbage collection). This drift is often legitimate and expected. Reconciling it away can break functionality.
3. Controller-initiated drift. This happens when two controllers fight over the same field. A classic case is a GitOps controller and a Terraform controller both managing the same ConfigMap, or ArgoCD and a custom operator both setting spec.replicas. I've seen this cause hot loops where each controller reverts the other's change every 30 seconds, spiking API server latency.
4. Failed or partial sync drift. A sync that applied 8 of 10 resources and failed on the 9th leaves the cluster in a half-reconciled state. Without atomicity or proper retry handling, you can have drift that looks like an intentional change but is actually an incomplete deployment.
Deciding What Qualifies as Actionable Drift
The key is to define drift not as "any difference" but as "any difference in fields you explicitly own in Git that should not be mutated by another actor." That definition pushes you toward explicit field ownership rules. For example, if HPA owns spec.replicas, then a replica count mismatch is not drift. If cert-manager owns metadata.annotations.cert-manager.io/*, those annotations are not drift. Documenting these ownership boundaries is what makes reconciliation predictable at scale.
Tuning Reconciliation Loops: Intervals, Timeouts and Retries in ArgoCD and Flux
Both ArgoCD and Flux run a reconciliation loop, but their defaults and failure modes differ significantly. Tuning these loops incorrectly is one of the fastest ways to overload etcd or miss critical drift.
ArgoCD uses a pull-based model where the application controller periodically compares Git to the cluster. The default comparison interval is 3 minutes (timeout.reconciliation), with a separate hard refresh and a sync retry with exponential backoff. Flux, via the kustomize-controller and helm-controller, reconciles on an interval you define per Kustomization/HelmRelease, typically 5-10 minutes for production, plus an immediate reconciliation on Git webhook events if you configure a notification provider.
In my experience, setting intervals too low is a common mistake for teams worried about drift. A 30-second interval across 200 applications means 400 Git pulls and API server LIST operations per minute. On EKS and GKE control planes with throttling, I've seen this generate 429 Too Many Requests and actually delay detection. My starting point for production is 3-5 minutes for ArgoCD and 5 minutes for Flux, with webhook-triggered reconciliations to get near-immediate sync for Git pushes without constant polling.
Production-Ready Reconciliation Configuration
Here is a hardened ArgoCD Application definition that balances fast detection with safety. It enables automated sync but protects against flapping and requires pruning to be explicit:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: payment-service
namespace: argocd
spec:
project: production
source:
repoURL: https://github.com/org/gitops-repo
targetRevision: main
path: apps/payment/overlays/prod
destination:
server: https://kubernetes.default.svc
namespace: payment
syncPolicy:
automated:
prune: true
selfHeal: true
allowEmpty: false
syncOptions:
- CreateNamespace=true
- PrunePropagationPolicy=foreground
- PruneLast=true
retry:
limit: 5
backoff:
duration: 5s
factor: 2
maxDuration: 3m
Compare that to a Flux Kustomization with equivalent drift correction and retry semantics. Notice the explicit interval, retryInterval, and prune controls, plus health checks that gate reconciliation success:
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: payment-service
namespace: flux-system
spec:
interval: 5m
retryInterval: 2m
timeout: 2m
path: ./apps/payment/overlays/prod
prune: true
wait: true
force: false
sourceRef:
kind: GitRepository
name: gitops-repo
healthChecks:
- apiVersion: apps/v1
kind: Deployment
name: payment-api
namespace: payment
timeout: 5m
If you are operating multiple clusters, the strategies diverge further. ArgoCD ApplicationSets with generators give you centralized control over sync policies per environment, which I've found invaluable for progressive delivery. Flux's approach with Kustomize overlays and tenant-scoped Kustomizations is more decentralized. For a deeper comparison of deployment models, see ArgoCD in Production: Application Sets, Sync Strategies and Multi-Cluster Management and Flux CD for Kubernetes: GitOps Automation with Kustomize and Helm.
Three-Way Diffing and Field Ownership: How Controllers Actually Compare State
Understanding the diff algorithm explains why two teams with the same Git repo can see completely different drift results. Modern controllers do not do a simple string compare. They perform a strategic merge diff that considers OpenAPI schema, managedFields, and ignore rules.
ArgoCD's diff uses kustomize build + kubectl apply --dry-run=server under the hood, normalizing the Git manifests by applying server-side defaulting before comparison. It then compares that normalized desired state to the live object from the API server. Flux's kustomize-controller does something similar via server-side apply with field ownership validation, and its newer drift detection feature (enabled via spec.enableDriftDetection in some controllers) explicitly checks if live state has diverged for fields managed by Flux.
The nuance is in managedFields. When you apply via server-side apply, the API server records which manager owns which field. If Flux owns spec.template.spec.containers[*].image but HPA owns spec.replicas, a correct diff will only flag image drift as actionable. An incorrect diff that ignores managedFields will flag both.
Implementing Ignore Rules That Scale
Every serious GitOps deployment needs ignore rules. The goal is to reduce noise without hiding real drift. Here is a pattern I use for Deployments that are managed by HPA and mutated by Istio:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: api-with-hpa
spec:
ignoreDifferences:
- group: apps
kind: Deployment
jsonPointers:
- /spec/replicas
- group: apps
kind: Deployment
jqPathExpressions:
- .spec.template.metadata.annotations."sidecar.istio.io/revision"
- .spec.template.metadata.annotations."traffic.sidecar.istio.io/includeInboundPorts"
- group: ""
kind: Service
jqPathExpressions:
- .spec.clusterIP
- .spec.clusterIPs
For Flux, the equivalent is done via spec.postBuild.substitute exclusions or by marking fields as not owned, and at the cluster level via patches that tell the controller to ignore certain managedFields. I've found that centralizing these ignore rules in a shared library — rather than letting each team invent their own — cuts drift alert noise by 70-80% in our environments. Document them clearly, because every ignore rule is a deliberate blind spot you are accepting.
| Capability | ArgoCD | Flux CD | Terraform Controller (TF-Controller / Crossplane) |
|---|---|---|---|
| Reconciliation Trigger | Poll interval (default 180s) + webhook + manual sync | Per-resource interval (e.g., 5m) + GitRepository notify | Drift detection interval (default 5m) + plan on change |
| Diff Mechanism | Normalized three-way diff with dry-run, respects ignoreDifferences | Server-side apply diff with managedFields ownership | Terraform plan diff; flags any state mismatch vs .tf files |
| Self-Healing | Optional per-app (selfHeal: true); reverts live drift automatically | Automatic on next interval unless suspended; no global selfHeal flag | Auto-apply can re-apply; otherwise reports drift only |
| Pruning Behavior | Explicit prune: true; with PruneLast and propagation policies | prune: true with wait and ordering; respects dependsOn | Drift may show deleted resources as tainted; requires apply to prune |
| Best For | Multi-tenant UI-driven workflows, ApplicationSets, manual sync approval | Headless, Git-native automation with Helm/Kustomize at scale | Infrastructure drift (cloud resources) complementary to cluster drift |
When Not to Reconcile: Exclusions, Pruning Guardrails and Manual Sync Windows
Automatic reconciliation is powerful until it automatically deletes the wrong thing. I learned this after an early pruning incident where a renamed Kustomization path caused ArgoCD to see all previous resources as orphaned and delete a production namespace. We had prune: true without PruneLast or sync windows, so there was no safety net.
There are three situations where you should pause or limit reconciliation:
Legitimate mutable fields. As discussed, HPA replicas, VPA recommendations, and operator-managed annotations should be ignored, not reverted. Self-healing should never fight an autoscaler.
Ephemeral and out-of-band resources. Jobs created by CronJobs, debug pods, or resources created by operators (like Prometheus Operator creating ServiceMonitors) should not be pruned just because they are not in Git. Use label selectors and sync options like Replace=true only where needed, and scope pruning to known namespaces.
High-risk windows. During migrations, database schema changes, or incident response, you want to freeze syncs. Both systems provide this. In ArgoCD, use sync windows or set automated: null temporarily. In Flux, use flux suspend kustomization or spec.suspend: true. In my teams, we enforce sync windows for production databases via an ApplicationSet policy so no automated sync can run during the backup window, regardless of what a developer pushes.
A practical guardrail is to require manual sync for destructive operations. Set automated.prune: false for critical applications and use ArgoCD's sync phases and waves to order deletions last. Flux's dependsOn achieves similar ordering. Pair this with GitOps Observability: Tracking Deployments, Rollbacks and Change Velocity so you have an audit trail of who reconciled what and when, rather than discovering deletions from missing pods.
Observing Convergence: Metrics, Alerts and Audit Trails That Prove Sync
Drift detection is only useful if someone is notified and can act. The controllers expose rich metrics that you should be alerting on, not just dashboarding.
For ArgoCD, the key metrics are argocd_app_sync_status (0 Synced, 1 OutOfSync), argocd_app_health_status, and argocd_app_reconcile_bucket which tracks how long reconciliation takes. I alert on OutOfSync > 15 minutes for production apps, excluding those with known ignored differences. For Flux, monitor gotk_reconcile_condition{type="Ready"} and gotk_reconcile_duration_seconds per Kustomization/HelmRelease. A Ready=False with reason DriftDetected or ReconciliationFailed should page the owning team, not just the platform team.
Logs alone are not enough. You need an audit trail that ties Git commits to cluster state. Both ArgoCD and Flux record the Git SHA they reconciled to in the Application/Kustomization status. Export that as a metric or log field and correlate it with your CI pipeline. I've found that the most valuable dashboard is not "is the app Synced?" but "how long does it take from Git push to cluster convergence, and how often does it revert?" That change velocity and sync success rate tells you whether reconciliation is healthy or thrashing.
Finally, test your drift response. We run a weekly chaos job in staging that intentionally patches a Deployment image tag via kubectl set image and verifies that the controller reverts it within the expected interval and emits the correct event. If your reconciliation loop cannot correct intentional drift in staging, it will not correct accidental drift in production. Treat drift detection as a control plane feature with an SLO, measure its mean time to detection and mean time to remediation, and tune intervals until you meet it.
Frequently Asked Questions
How quickly should drift be reconciled in production?
For most production workloads, a 3-5 minute reconciliation interval with webhook-triggered immediate sync on Git push is the right balance. Faster than 1 minute creates API server load and risks throttling without meaningful benefit, while longer than 10 minutes increases your window of inconsistency during incidents. Critical apps with automated selfHeal can be tuned to 2 minutes, but pair that with proper ignoreDifferences so you don't fight autoscalers. Measure your actual mean time to detection from your controller metrics and adjust from there.
Should I enable selfHeal and auto-pruning for all applications?
No. Enable selfHeal selectively. I recommend selfHeal for stateless services where Git should always win, but disable it or use ignored differences for workloads owned by autoscalers or operators. For pruning, use PruneLast and foreground propagation, and consider disabling automated pruning for stateful or critical namespaces — require a manual sync with explicit approval for deletions. This prevents a bad Git push or path rename from mass-deleting resources.
What's the difference between drift detection and continuous reconciliation?
Drift detection is the read-only comparison of Git desired state vs live state, often reported as Synced/OutOfSync or Ready/NotReady without changing the cluster. Reconciliation is the write operation that applies changes to converge live state to desired state. Good GitOps separates the two: you always want drift detection running, but reconciliation can be manual, automated on an interval, or automated only for specific fields. This separation lets you alert on drift without automatically reverting legitimate temporary changes during an incident.
How do I handle secrets that appear as drift but shouldn't be reconciled?
Never store raw secrets in Git and never let the controller revert secret values managed externally. Use a secret management pattern where Git stores a reference (e.g., ExternalSecret or SealedSecret) and the controller manages the reference, not the plaintext value. This way, the diff compares the ExternalSecret spec in Git vs live, not the generated Secret's data. See GitOps Secret Management: Sealed Secrets, SOPS and External Secret Operator for detailed patterns on keeping secret drift out of your reconciliation loop entirely.