Why did my Kubernetes change disappear? Argo CD Self-heal explained
DEV Community

Why did my Kubernetes change disappear? Argo CD Self-heal explained

You scale a Deployment directly in Kubernetes. Later, it returns to the replica count stored in Git. Before treating that as a failed command, check the Argo CD Application's sync policy. Self-heal may be restoring the desired configuration.

One setting, two different values

Consider one Argo CD-managed Deployment named demo-app in a disposable namespace named gitops-demo. No autoscaler or other controller manages its replica count, and /spec/replicas is included in Argo CD's comparison and synchronization.

Git contains this fragment of the Deployment manifest:

# Deployment manifest fragment; not a complete manifest.
spec:
  replicas: 2

Someone changes the live Deployment to four replicas. Git still requests two. Kubernetes supports this kind of direct scaling through kubectl scale; it changes the live resource rather than your source file.

Location Replica setting
Desired configuration in Git 2
Live Deployment configuration 4

Argo CD compares desired configuration with live resources. Here, the tracked difference is live drift. OutOfSync identifies a mismatch; it doesn't tell you whether the manual change was useful, mistaken, or temporary.

Core concepts

What Self-heal adds

Automated sync can apply changes from the tracked source without someone starting a manual sync. Self-heal enables automated synchronization in response to live-state deviations when that source hasn't changed.

For this example, the Application policy fragment is:

# Argo CD Application fragment; not a Deployment setting.
spec:
  syncPolicy:
    automated:
      enabled: true
      selfHeal: true

With that policy active, Argo CD can attempt to restore the Deployment's replica setting to two. This describes a configuration change, not a promise that the application becomes ready immediately.

Self-heal does not write the manual value of four back to Git. See the automated sync policy for the exact behavior and settings.

Try it in a disposable environment

Use an existing demo Application named demo-app that manages this Deployment. The commands below change cluster state; confirm your context and namespace first. Do not run them against a production workload.

# Confirm the destination before changing anything.
kubectl config current-context
kubectl -n gitops-demo get deployment demo-app

# Deliberately introduce drift in the demo environment.
kubectl -n gitops-demo scale deployment/demo-app --replicas=4

# Inspect Argo CD's comparison and the Deployment setting.
argocd app get demo-app --refresh
argocd app diff demo-app
kubectl -n gitops-demo get deployment demo-app --watch

If reconciliation happens quickly, you may miss the temporary four-replica setting. Observe the Application's operation history as well. The diff command exits with code 1 when differences exist, so a script should handle that result deliberately. Diff command reference

Make an intentional change durable

If four replicas is the intended lasting configuration, change spec.replicas to 4 in the source manifest, review it, and commit it to the revision Argo CD tracks. Then synchronize through your configured workflow.

Now the desired setting itself is four. The deployment configuration carries the decision, instead of depending on an unrecorded live edit.

Check who owns the field

An autoscaler may legitimately manage replicas. Don't apply this example unchanged to that situation. Argo CD supports comparison customization for fields owned elsewhere. Ignoring a field during comparison and omitting it during synchronization are distinct configuration choices; RespectIgnoreDifferences affects the latter. Diff customization, sync options

For urgent live edits, agree on the exception workflow before an incident. Record what changed, decide whether Git should adopt it, and restore the intended automation afterward.

How does your team keep emergency cluster edits and Git aligned?

I'm Ameni Ben Saada, a software engineer working across full-stack development and cloud delivery. My work: amenibensaada.tn.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.