LOOP · The DevOps Codex
Ch 07 · GitOps
Chapter 07 · Git as the Source of Truth

GitOps — a controller that closes the loop on intent and reality

GitOps is the operating model in which the desired state of every running system is declared in a Git repository, and an in-cluster agent continuously reconciles reality to that declaration. The pipeline stops at git push; from there, controllers pull. Drift becomes a diff; rollback becomes a revert; audit becomes git log.

7.1 · What GitOps is

Definition. GitOps is a set of practices, coined by Alexis Richardson of Weaveworks in August 2017, for managing infrastructure and applications by which:

  1. The entire desired system state is described declaratively in version control.
  2. Approved changes are merged via the same review process used for code.
  3. One or more software agents inside the target environment pull the declarations and apply them.
  4. The same agents continuously verify the running state against the declared state and remediate drift.
The radical idea is not "store YAML in Git" — everyone does that. It is the controller: a process inside the cluster that owns reconciliation and treats Git as truth, not a stash.

7.2 · The four GitOps principles (OpenGitOps v1.0, CNCF, 2022)

PrincipleDefinitionImplication
DeclarativeThe system's desired state is expressed declaratively (what, not how).Manifests, not scripts. Kustomize, Helm, Terraform HCL all qualify.
Versioned & immutableState is stored such that changes are immutable, with a complete version history.Git, OCI artefacts. Every state has a SHA.
Pulled automaticallySoftware agents automatically pull the declared state from the source.Controller-in-cluster, not pipeline-into-cluster.
Continuously reconciledAgents continuously observe actual state and attempt to reconcile to declared state.Self-healing; drift is corrected without human action.

The OpenGitOps Working Group sits inside the CNCF App Delivery TAG; v1.0 of the principles was ratified in 2022. Argo CD and Flux are the two CNCF graduated implementations.

7.3 · GitOps vs the push CD model

Push CD (legacy) Git CI/CD Cluster (kubectl) CI holds prod creds · firewall must allow CI → cluster GitOps (pull) Git Cluster Argo / Flux controller pulls Git from inside the cluster · no inbound creds
DimensionPush CDGitOps (Pull)
Credential directionCI holds cluster creds (outbound)Cluster holds Git creds (outbound only)
Network surfaceInbound to API serverNone inbound required
DriftInvisible until next deployDetected and auto-healed
Audit trailCI logs (mutable)git log (immutable)
RollbackRe-run pipelinegit revert
Multi-clusterN×credentials in CIOne controller per cluster

7.4 · Argo CD

Argo CD (CNCF Graduated, 2022) is the most widely adopted GitOps controller. Its core resource is the Application: a binding between a Git repo path and a target cluster namespace.

  • Application CRD — source (repo, path, revision), destination (cluster, namespace), syncPolicy (auto/manual, prune, selfHeal).
  • App-of-Apps — one root Application whose source repo contains child Applications; a single sync brings up an entire environment.
  • ApplicationSet — templating + generators (List, Git, Cluster, SCM-Provider, Matrix, Merge) for fleets of similar apps.
  • Sync waves & hooks — annotate resources with argocd.argoproj.io/sync-wave: "-1" to order; PreSync / Sync / PostSync / SyncFail hooks run jobs (e.g. DB migrations).
  • AppProjects — multi-tenancy boundary: allowed sources, destinations, cluster-scoped resources, roles.
  • Argo CD Notifications — fan-out sync events to Slack, Teams, GitHub deployment statuses.
  • Argo CD Image Updater — companion that bumps image tags in Git on new registry pushes.
# Argo CD Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: { name: web-prod, namespace: argocd }
spec:
  project: production
  source:
    repoURL: https://github.com/acme/platform-config
    path: apps/web/overlays/prod
    targetRevision: main
  destination: { server: https://kubernetes.default.svc, namespace: web }
  syncPolicy:
    automated: { prune: true, selfHeal: true }
    syncOptions: [ "ApplyOutOfSyncOnly=true", "CreateNamespace=true" ]

7.5 · Flux

Flux (CNCF Graduated, 2022) is the second canonical implementation. Flux is a set of focused controllers — each a separate CRD — that compose into a pipeline.

ControllerCRDPurpose
SourceGitRepository, HelmRepository, OCIRepository, BucketPulls and caches source artefacts.
KustomizeKustomizationBuilds and applies Kustomize overlays.
HelmHelmReleaseInstalls / upgrades Helm charts declaratively.
NotificationProvider, Alert, ReceiverWebhook in/out for events.
Image AutomationImageRepository, ImagePolicy, ImageUpdateAutomationScans registries, commits new tags to Git.
  • OCI as source. Flux can pull manifests from OCI registries (Helm OCI, image artefacts) — closer-to-immutable than a moving Git branch.
  • Multi-tenancy. Namespace-scoped controllers with impersonation via ServiceAccount.
  • Flagger (same project) plugs in for progressive delivery — same GitOps controller drives canaries.

7.6 · Alternative GitOps platforms

  • Jenkins X — opinionated GitOps for Kubernetes built on Tekton + Lighthouse + Nexus; CDF project.
  • Rancher Fleet — SUSE's multi-cluster GitOps engine, optimised for large edge fleets (thousands of clusters).
  • Codefresh GitOps Cloud — managed Argo CD with Argo Rollouts + Workflows; enterprise control plane.
  • Akuity Platform — hosted Argo CD by the project maintainers.
  • Werf — Flant's GitOps + build tool combining Helm and Buildah.
  • Kapp Controller (Carvel) — VMware Tanzu's reconciler over Carvel manifests.

7.7 · Repository structure patterns

PatternLayoutPros / cons
Single config monorepoOne repo, dirs per app + per envEasy cross-cuts; can grow huge.
App + config reposApp code in one repo; manifests in anotherSeparation of concerns; coordination overhead.
Env-per-branchdev / stg / prod branchesFamiliar; merge conflicts; obscures promotion intent.
Env-per-directory (preferred)overlays/dev, overlays/prod in mainSingle source of truth; promotion = PR copy.
App-of-appsRoot app references child appsBootstrap entire env from one Application.
ApplicationSet / Fleet bundleTemplated apps per cluster via generatorsScales to 100s of clusters.
# Kustomize overlay tree
platform-config/
├── base/web/{deployment,service,kustomization}.yaml
└── overlays/
    ├── dev/{kustomization.yaml,patches/*}
    ├── stg/{kustomization.yaml,patches/*}
    └── prod/{kustomization.yaml,patches/*}

7.8 · Promotion patterns

  • Image-tag promotion via PR. CI builds image, opens a PR bumping the tag in overlays/stg; merge triggers Argo sync; QA passes; subsequent PR bumps overlays/prod.
  • Argo CD Image Updater — write-back commits to Git when a new tag matches a constraint (semver, regex, digest).
  • Flux Image Automation — equivalent in the Flux stack via ImagePolicy.
  • Promoter tools — Kargo (Akuity, 2024), Codefresh promoter pipelines, Telefonistka — model env stages as a graph and automate the copy.
  • Pinning by digest. Promote image@sha256:... not :v1.2.3 — eliminates tag mutability risk.

7.9 · GitOps for IaC

Kubernetes manifests were the original target, but the same loop applies to anything declarative.

  • Crossplane (CNCF Incubating) — model AWS/GCP/Azure resources as Kubernetes CRDs; Argo/Flux reconciles them as if they were pods.
  • Terraform Controller (Weaveworks/Flux) — runs terraform plan/apply driven by a Terraform CRD.
  • Atlantis — PR-driven Terraform; comments on plans, applies on merge. The "Git-driven" Terraform default.
  • Env0, Spacelift, Scalr, Terraform Cloud — managed runners with policy gates, state management, drift detection.
  • Pulumi Deployments / Operator — same loop for Pulumi programs.
  • Argo CD with Terraform plugin — render Terraform-as-CRDs and reconcile from Git.

7.10 · Multi-cluster fleet management

ToolApproach
Argo CD ApplicationSetGenerators (Cluster, List, Matrix, SCM, Git directory) template apps across clusters.
Flux + Fleet (Rancher)Per-cluster agents, bundles distributed from a management cluster.
Cluster API (CAPI)Declarative cluster lifecycle — clusters themselves become CRDs.
Open Cluster Management (OCM)Red Hat / IBM multi-cluster orchestration with policy & placement.
KarmadaFederation v2 successor; propagate workloads with overrides per cluster.
Google Config Sync / AnthosHosted GitOps for GKE + on-prem.

7.11 · Drift detection & remediation

  • Auto-heal. Argo selfHeal: true / Flux default — any out-of-band change is reverted within seconds. Use in prod; warn in dev (devs ssh-poke and complain when their kubectl edit vanishes).
  • Manual sync. Drift is reported but action is human — common for stateful or regulated workloads.
  • Policy gates at sync time. Kyverno, OPA Gatekeeper, jsPolicy, Polaris validate manifests before they hit the API server; Argo CD supports SyncWindow + admission hook integration.
  • Diff alerts. Argo CD Notifications + Slack on every drift event.
Drift is a symptom, not a fault. A cluster that drifts every Tuesday at 02:00 is being modified by someone or something — find them. The reconciler is a smoke detector, not a fire suppressor.

7.12 · GitOps for ML & data

  • Kubeflow Pipelines + Argo Workflows — pipeline runs declared as CRs; reconciled by GitOps.
  • MLflow Model Registry with promotion stages (Staging → Production) gated through PRs.
  • Feast (Feature Store) — feature definitions in YAML, reconciled by GitOps; serving infra follows.
  • dbt with continuous deployment — dbt models + tests in Git, reconciled by dbt Cloud or Argo Workflows.
  • Dagster, Prefect — workflow specs as code; Git as the source of truth for the orchestrator.
Cross-references
  • Ch 02 — Git workflows determine your promotion model.
  • Ch 04 — CI builds artefacts; GitOps deploys them. Clear hand-off.
  • Ch 05 — Argo Rollouts / Flagger plug into the GitOps loop.
  • Ch 10 — Terraform + GitOps via Crossplane / Atlantis.
  • Ch 18 — Platform engineering teams ship GitOps as a paved road.

7.13 · Self-check

Q1 · Which of the four OpenGitOps principles ensures that an out-of-band kubectl apply is reverted automatically?
Declarative
Versioned & immutable
Pulled automatically
Continuously reconciled
Q2 · Why does the pull model in GitOps reduce the credential blast radius compared with push CD?
The cluster encrypts manifests at rest.
The controller lives inside the cluster, so only an outbound read of Git is needed — no inbound credentials from CI.
Argo CD signs every commit with cosign by default.
Pull mode disables RBAC.
Q3 · In Argo CD, which construct is best for templating one Application per cluster across a fleet?
App-of-Apps
ApplicationSet with the Cluster generator
AppProject
Sync waves