The idea
GitOps runs a system from a Git repository. The repository holds the desired state: files saying what should run. An agent inside the cluster keeps the live system matching those files, so people change the system by changing the files.
Change it in Git
web.yaml is a Kubernetes Deployment. It is declarative: it says what we want, not the steps to get there. Line 5 asks for 2 replicas, two copies of the web server, each in its own pod (the smallest unit Kubernetes runs).
Traffic grows, so a developer changes line 5 to replicas: 3 and opens a pull request. A teammate reviews and merges it. Git records a new commit; every earlier version stays in the history, untouched.
The agent at work
The GitOps agent, such as Argo CD or Flux, runs inside the cluster and pulls the repository on a timer; Argo CD checks every 3 minutes by default. Because the cluster pulls, the build system never needs keys to the cluster.
The agent compares the two states. Git wants 3 replicas; the cluster runs 2. They differ, so the app is marked OutOfSync. Compare, then act: this loop is how every Kubernetes controller works.
The agent applies web.yaml to the cluster. Kubernetes' Deployment controller sees 3 pods wanted but 2 running, and starts a third. Live now matches Git, 3 = 3, so the app is Synced.
Drift and rollback
Late one night someone types kubectl scale deployment web --replicas=1. Two pods stop. The cluster has drifted: it no longer matches Git, and no review or commit records who did it or why.
The agent keeps watching, spots the drift and applies the Git version again: back to 3 pods. Argo CD does this when self-heal is switched on; Flux re-applies on every interval. Git wins over hand edits.
Traffic falls, so the team runs git revert on commit #2. That adds commit #3, which undoes it. The agent pulls it and scales back to 2 pods. A rollback is just another reviewed commit.
The principles
OpenGitOps names four principles: the desired state is declarative, versioned and immutable, pulled automatically and continuously reconciled. In the cloud: Flux on Azure AKS, Config Sync on Google GKE, Argo CD or Flux on AWS EKS.
What happens
;; step 1/10 · gitops Git repository = desired state (files) cluster = live state (what runs) GitOps agent = keeps live == desired to change the system: change Git
Two control loops are at work: the GitOps agent makes the Deployment object match Git, and Kubernetes’ own Deployment controller makes the running pods match the Deployment. The figure shows them as one step. In Argo CD, automatic sync and self-heal are opt-in settings (syncPolicy.automated with selfHeal: true). Flux re-applies the manifests on every reconciliation interval, which also corrects drift.