Skip to main content

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

flowchart LR A[App repo: code] --> B[CI builds image] B --> C[PR bumps image digest] C --> D[(Config repo)] D --> E[ArgoCD or Flux] E --> F[Cluster] classDef code fill:#8B5CF6,color:#FFFFFF classDef tool fill:#326CE5,color:#FFFFFF classDef store fill:#475569,color:#FFFFFF class A,B code class C,E tool class D,F store
TEXT
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

YAML
syncPolicy:
automated:
selfHeal: true # revert manual changes to match Git
prune: true # delete resources removed from Git

A 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
Tip

During a declared incident, pause self-heal before an emergency change, then commit the change to Git afterward so both states converge.

Remember

Git records intended changes. For the exact time something was applied, also check the agent's own events and logs.

Security

Whoever can merge to the config repo's protected branch effectively has cluster access. Protect that branch with required reviews.

Common Mistake

Keeping a manual kubectl apply escape 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.

Found a mistake, an outdated step or a broken link?