GitOps
GitOps is an operating model where Git holds the desired state of infrastructure and an in-cluster agent continuously pulls it and reconciles the live system to match.
Understanding GitOps
What Is GitOps and What Are Its Principles
GitOps treats Git as the single source of truth for what should be running. Changes are made through commits and pull requests, and an agent such as ArgoCD or Flux inside the cluster applies and keeps enforcing them. Every production change then has an author, a timestamp, and a reviewer.
The four commonly cited principles:
- Declarative: desired state is data such as manifests, Helm values, or Kustomize overlays, not a sequence of commands.
- Versioned and immutable: state lives in Git, so you get history, diffs, and revert with
git revert. - Pulled automatically: the agent pulls from Git, nothing external pushes into the cluster.
- Continuously reconciled: the agent keeps comparing live state with Git and corrects drift.
Push CD vs Pull GitOps
| Model | Cluster access |
|---|---|
| Push (traditional CI) | CI holds credentials to every cluster |
| Pull (GitOps) | Cluster only needs read access to Git |
With push, a compromised CI system can reach production. With pull, the blast radius of CI is smaller because it only writes to Git.
The Two-Repository Pattern
app-repo/ config-repo/ src/ base/ Dockerfile deployment.yaml .github/workflows/ service.yaml overlays/ staging/ production/CI builds and tests the app, then opens a pull request against the config repo. A human reviews that PR before the new digest reaches the production overlay.
Drift Detection and Self-Heal
syncPolicy: automated: selfHeal: true # revert manual changes to match Git prune: true # delete resources removed from GitA manual kubectl edit is detected on the next reconcile and either reported or reverted, depending on policy.
Troubleshooting
| Symptom | Check | What to Look For |
|---|---|---|
| Cluster does not match Git | Agent sync status | Paused sync or manual policy |
| Manual fix keeps vanishing | Sync policy | selfHeal working as designed |
| New manifest not appearing | Source path and branch | Config points at the wrong folder |
TipDuring a declared incident, pause self-heal before an emergency change, then commit the change to Git afterward so both states converge.
RememberGit records intended changes. For the exact time something was applied, also check the agent's own events and logs.
SecurityWhoever can merge to the config repo's protected branch effectively has cluster access. Protect that branch with required reviews.
Common MistakeKeeping a manual
kubectl applyescape hatch for emergencies. It breaks the audit trail. Route emergency changes through Git on a fast review path.
Frequently Asked Questions
How is GitOps different from a pipeline that runs kubectl apply?
A traditional pipeline pushes changes once, using credentials to the cluster. In GitOps an agent inside the cluster pulls from Git and keeps reconciling, so drift is detected and the pipeline never needs cluster credentials.
What happens if I change something manually in a GitOps cluster?
The agent will detect the drift and, with self-heal enabled, revert it on the next sync. Commit the change to Git instead so it persists.
Does GitOps only work with Kubernetes?
It is most common with Kubernetes, but the idea of versioned declarative state reconciled by an agent also applies to infrastructure through tools such as Crossplane or Terraform controllers.