Skip to content

Lesson 1 of 9 · 22m

Desired State Is the API

Learn why GitOps is a control-loop discipline rather than a deployment script, and how to draw the boundary between declarative state and imperative operations.

The worst GitOps incident I ever watched was caused by a helpful engineer. Production was down, he ran kubectl scale by hand, traffic recovered, and ten minutes later the controller scaled the workload back down because Git still said two replicas. Nothing malfunctioned. The system did exactly what we told it to do. GitOps does not make operations easier; it makes operational truth explicit.

Git is the control-plane client

The core loop is simple:

desired state in Git
        |
        v
controller observes cluster ----> diff
        |                         |
        +-------- converge <------+

Flux and Argo CD are continuous controllers. They do not merely apply YAML when a commit lands. They repeatedly compare declared state with observed state and converge toward the declaration. If you remember only one thing as a new operator, remember this: in GitOps, Git is not a backup of configuration. It is the API you use to operate the platform.

Imperative commands are writes outside the contract

This looks harmless in an emergency:

kubectl -n checkout scale deploy/api --replicas=8
kubectl -n checkout set image deploy/api api=ghcr.io/sudosecurityorg/checkout-api:hotfix-7

It may save the minute and cost the hour. The next reconciliation can undo the change, or worse, partially undo it. If you must use imperative commands, annotate the exact change and immediately open the pull request that makes Git agree with reality. Mature teams treat manual mutation as an incident input, not as a deployment mechanism.

Drift is a signal, not merely a difference

When cluster state differs from Git, ask who wrote the change: an autoscaling controller, a mutating admission webhook, a human, another GitOps controller, or a broken rollout. Some drift is intentional and must be ignored. Some drift is the first symptom of an unauthorized control path. Do not configure broad ignore rules just because the diff is noisy.

Field notes

  • Reconciliation is not idempotence magic; badly written resources can still flap forever.
  • Controllers converge to what Git says, not what you meant.
  • Every manual change should end in one of two states: represented in Git or deliberately excluded with a documented ignore rule.
  • kubectl diff is a preview, not proof of what the GitOps controller will decide.
  • If two automation systems manage the same fields, you do not have GitOps — you have a distributed fight.

Was this lesson helpful?

Sign in to rate