Overview
Curated: · Written: · Reviewed:
GitOps
In one line
A controller in or beside the cluster pulls declarative desired state from a Git revision, diffs it against live objects, and applies corrections. Reach for it when many clusters must converge on the same reviewed state, or when clusters sit behind NAT or at the edge, where inbound CI access is impractical.
Key definitions
- Desired state: rendered manifests at one Git revision. Git holds this, never live state.
- Observed state: what the API server reports for managed objects at comparison time.
- Reconciliation: fetch, render, diff, apply, report. Runs on an interval and on webhook triggers.
- Synced / OutOfSync: the diff result for managed fields. It says nothing about health.
- Self-heal / prune: self-heal reverts unauthorized drift on the next pass; prune deletes live objects that Git no longer declares.
- Immutable artifact: an image referenced by digest (
@sha256:...), not a mutable tag.
Formulas and complexity
Hypothetical figures: poll 3 min, sync 20 s, so a manual change can persist up to 3 min 20 s before revert. Argo CD's default app refresh interval is 3 minutes at the time of writing; confirm against the version you run.
How it works
The agent fetches desired state, renders it (Helm, Kustomize or plain YAML), and compares each managed object with the API server's copy. A diff triggers an apply, and the outcome goes into status. Field ownership decides what the diff sees. HPA-owned replicas and server-defaulted fields need explicit ignore rules, or the loop fights the autoscaler.
When to use and when not to
| Situation | GitOps pull | Push from CI |
|---|---|---|
| Many clusters, drift must be corrected | Yes | No loop, drift persists |
| Clusters behind NAT or air-gapped | Yes, outbound only | Needs inbound access |
| Rapid dev iteration on throwaway environments | Often too slow | Simpler |
| Non-declarative systems (imperative migrations, external SaaS) | Needs adapters or hooks | Fits better |
| Stateful schema change | Git revert cannot undo it | Same problem, roll forward either way |
Traps interviewers probe
- "Synced means it's live and healthy." Synced means the comparison matched at that moment. Check health, rollout status and user-facing signals separately.
- "A tag is a version." Tags move. Deploy by digest, or a re-pushed tag changes what nodes pull mid-roll.
- "Self-heal just keeps things correct." It also erases live mitigations. Commit the emergency change to Git, or pause automation with a time bound.
- "Prune only removes what we deleted." Prune removes anything the Application owns that Git no longer declares, including objects moved to an unsynced path. Scope the inventory, protect namespaces, CRs and shared infrastructure, and never treat empty or failed rendering as an instruction to erase.
- "Revert the commit to roll back." Git reverts intent, not external state. Schema migrations, issued credentials and consumed messages stay changed. Roll forward or repair the data.
- "The agent is least-privileged because it runs in-cluster." It holds privileged write access. Scope it per application and namespace, and protect its tokens and service account.
Interview tips
Open with: "The desired state lives in Git, and a controller keeps the cluster converged to it. The agent enforces; it does not just report."
Expect these follow-ups:
- Why not have CI run
kubectl apply? No loop, CI holds cluster credentials, and no evidence after push time. - What if Git is down? Running workloads persist, new deploys stop, and you need last-known-good state and break-glass access.
- Self-heal reverted my hotfix. The fix was not reconciled into source, so the real question is field ownership.
- How do you handle secrets? Never plaintext in Git. Reconcile a reference through sealed secrets, an external secret operator or vault injection.
30-second outline:
- Desired state in Git, observed state in the cluster, and a controller that closes the gap.
- Pull model: outbound only, with no CI holding cluster credentials.
- Artifacts by digest; promotion is a reviewed commit that selects the digest.
- Drift policy per field: self-heal where trusted, ignore where another controller owns the field.
- Prune and migrations are the danger points: scoped deletion, and roll-forward for data.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.