GitOps
Running infrastructure from a Git repository: describe what should exist, let an agent in the cluster pull it and keep reality matching, and undo a release by reverting a commit.
In 30 seconds
GitOps keeps the description of your infrastructure, what should run, how many copies, which version, as files in a Git repository. That repository is the single source of truth.
An agent inside the cluster pulls the repository and keeps comparing it with what is really running. Wherever they differ it changes the cluster to match, including changes someone made by hand (drift).
So a release is a commit, the history is the audit log, and a rollback is a revert of that commit.
GitOps, step by step
Simplified: the commit hashes are shortened and invented. Automatic correction of drift is a setting; an agent can also only report it. Secrets such as passwords need extra care before they go into Git.
- Step 1: Changes made by hand. Two people look after a cluster by typing commands at it. Ana scales the web app to five copies; later Ben switches it to a new version. Each command works, but the cluster keeps no story of how it got here. Nobody can say what should be running, who changed it, or how to return to last week’s setup.
- Step 2: Describe it in Git. GitOps starts by writing down the state you want, not the commands to reach it: a file saying there should be three copies of web, version 1.0. The file lives in a Git repository, so every version of it is a commit with an author, a date and a reason. That repository becomes the single source of truth.
- Step 3: An agent pulls. A small program, the agent, runs inside the cluster. Every few minutes it fetches the repository and reads the latest commit. This is pull, not push: the cluster reaches out to Git, so no build server or laptop outside needs the keys to the cluster. Tools such as Argo CD and Flux work this way.
- Step 4: Reconcile. Having read the file, the agent compares it with what the cluster is really running. Git asks for three pods and there are none, so the agent creates them. Then it compares again, and again, forever. This loop of compare and correct is called reconciliation; when both sides match, the cluster is in sync.
- Step 5: A change is a commit. To release version 1.1, Ana does not touch the cluster. She edits one line of the file and commits it, usually through a pull request that a colleague reviews first. On its next fetch the agent sees commit b7e2, finds the cluster behind, and rolls out 1.1. The Git history doubles as the log of every change.
- Step 6: Drift is detected. During a busy evening Ben scales the app to five by hand, as he used to. The cluster no longer matches Git: it has drifted. On its next comparison the agent notices and reports the cluster out of sync. Set to heal automatically, it removes the two extra pods. A lasting change has to go through Git.
- Step 7: Rollback is a revert. Version 1.1 turns out to have a bug. Rolling back needs no special tool: git revert b7e2 adds a new commit, c4d8, that undoes that change, so the file says web:1.0 again. The agent sees a new commit like any other and rolls the cluster back. Nothing is erased; the history shows the release and its undoing.
Try it yourself
Learn this first
Learn next
- ObservabilityWorking out what a system is doing inside from the logs, metrics and traces it emits. Beginner
- Feature flagsShip code switched off, then turn it on for a few users, then for everyone. Beginner
- Disaster recovery (RPO and RTO)How much data you can lose, how long you can be down, and what each costs. Intermediate
Spotted a mistake on this page?