Appearance

GitOps and drift reconciliation

Follow a Git revision into a running cluster and decide who should repair a conflicting change.

What you will understand

  • Trace a GitOps controller’s source revision, render, comparison, sync, and health checks.
  • Distinguish automatic sync, self-healing, and pruning.
  • Inspect field ownership before restoring a value changed by hand.

Builds on: Watches and server-side apply, Ownership and failure recovery

How a Git change reaches Kubernetes

A teammate changes a live ConfigMap to troubleshoot checkout. The fix works for today, but the repository still declares the old value. The live object and the source disagree. GitOps uses versioned, declarative configuration as the source of desired state and a controller to compare and reconcile that state with the environment. Someone reviewing a change can see the proposed configuration, and someone responding to an incident can identify the revision the controller last observed.

Follow one revision in the scene. The controller fetches the source, renders manifests if needed, compares them with live resources, and attempts a sync when configured to do so. It then evaluates health using its knowledge of the resources. Fetching a revision, applying its manifests, and verifying that an app works are separate checkpoints. A green diff can coexist with a broken backend.

Follow a reviewed Git revision into Kubernetes

The GitOps controller renders the recorded revision, compares with live state, and syncs according to policy. App health is a separate observation.

  1. RepositorySupply a known revision
    GitOps controllerThe controller knows which declared state it is comparing.
  2. GitOps controllerRender, compare and sync
    Kubernetes APIThe controller submits changes its policy allows.
  3. Workload and controllersReport status after reconciliation
    GitOps health assessmentSync and workload health can be inspected separately.
Follow the sequence

The GitOps controller renders the recorded revision, compares with live state, and syncs according to policy. App health is a separate observation.

Argo CD is an optional add-on; the mandatory local exercise models the ownership loop with kubectl.

Inspect the drift repair

Compare a declared checkout setting with the live ConfigMap after an emergency edit, then restore the approved value.

1 / 4

From Declared sourceTo Comparison

Apply the declared setting

The lab starts with resources.yaml declaring git-declared. Applying it creates the live ConfigMap with the same value.

Declared / live release
Before
git-declared / absent
After
git-declared / git-declared
Apply the declared setting

The lab starts with resources.yaml declaring git-declared. Applying it creates the live ConfigMap with the same value.

The operator compares and applies the declaration by hand in this exercise. A GitOps controller can automate these decisions under its sync policy.

If the comparison shows drift, has the live value changed back yet?
Reveal prediction answer

Comparison reports the difference. A successful write is needed to restore the approved declaration.

Read data.release after the manual patch and after applying the declaration again.

Detect and repair drift in the platform lab
Explore another case

Open Inspect the drift repair to see what the comparison reports after a manual edit, then verify the live value after applying the approved declaration again.

Decide when to sync, repair drift, and prune

In Argo CD, for example, automated sync, self-healing of live drift, and automatic pruning are distinct controls. A manual change can remain until another sync if self-healing is disabled. Pruning authorizes removal of resources that the source no longer declares, subject to the application’s settings. Before allowing that behavior, inspect what the controller tracks and how it handles resources whose state must be retained. Check compatibility with your Kubernetes version before installing a production controller.

Inspect a manual change before restoring it

Use the ConfigMap as a small declaration. The module’s commands apply it with field manager kv-gitops, then change the live value with a manual patch. Inspect the declared value, the live value, and the managers. The final command deliberately takes ownership of the changed field in the disposable lab. In a shared environment, choose whether to keep the emergency value by committing it, undo it through the repository, or coordinate an intentional change in ownership.

apiVersion: v1
kind: ConfigMap
metadata:
  name: m19
  namespace: kv-lab
  labels:
    lab: m19
data:
  release: git-declared
# Run from the downloaded m19 directory.
kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-gitops -f resources.yaml
kubectl --context kind-kv-lab -n kv-lab patch configmap m19 --type=merge -p '{"data":{"release":"manual-drift"}}'
kubectl --context kind-kv-lab -n kv-lab get configmap m19 -o yaml --show-managed-fields
# Intentional takeover of this disposable lab field only.
kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-gitops --force-conflicts -f resources.yaml

Who may restore an owned field after a manual edit?

Inspect both the declared and live value and their field managers before granting or forcing a different manager to own the field.

  1. Apply the declared value

    kv-gitops applies data.release as git-declared.

  2. Observe manual drift

    A patch changes the field and may transfer ownership; inspect both live value and managedFields.

  3. Restore with an explicit ownership decision

    The lab intentionally uses force-conflicts for this disposable field, restoring the source value and ownership contract.

The drift exercise uses an ordinary patch; conflicting SSA by a second manager is a separate API operation.

The platform operations lab models drift repair with server-side apply. It does not run a background GitOps controller. Observe what persists until the next apply and compare that with the automatic reconciliation shown in the scene.

Keep emergency changes reviewable

A controller depends on its source, credentials, rendering tools, and cluster permissions. Diagnose a failed fetch differently from a sync rejected by admission. For emergency edits, document who made the edit, how long it should remain, and how the team will restore a single source of intent.

Check your understanding

A bad live edit keeps returning to the repository’s old value after you patch it again. Where should a lasting fix go?

Change the versioned desired state and let the controller apply the reviewed revision. If the live edit is part of emergency response, coordinate the reconciliation policy while the approved value is prepared.

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu