CLUSTER#1r=2#2·#3·WANT2LIVE2SYNC=1apiVersion: apps/v12kind: Deployment3metadata: {name: web}4spec:5 replicas: 2 replicas: 36 selector: {matchLabels: {app: web}}7 template:8 metadata: {labels: {app: web}}9 spec:10 containers:11 - {name: web, image: "nginx:1.27"}web.yaml
Blocks: developer, Git repository, GitOps agent, pods, kubectl terminalFront: web.yaml (desired state) and the WANT / LIVE / SYNC readoutEnvelope: one change on its wayGitOps: the Git repository holds the desired state (web.yaml, a Kubernetes Deployment), and a GitOps agent inside the cluster keeps the live state matching it. A commit changes replicas from 2 to 3; the agent pulls, compares WANT with LIVE, and applies, so a third pod starts. A hand edit with kubectl drifts the cluster to 1 pod; the agent heals it from Git. A git revert rolls it back to 2. The four principles are from OpenGitOps v1.0.0, written by the CNCF GitOps Working Group. GitOps is not tied to Kubernetes, but Kubernetes is where it is used most, because Kubernetes objects are already declarative.

The idea

  1. 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

The agent at work

Drift and rollback

The principles

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.