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:
- The entire desired system state is described declaratively in version control.
- Approved changes are merged via the same review process used for code.
- One or more software agents inside the target environment pull the declarations and apply them.
- The same agents continuously verify the running state against the declared state and remediate drift.
7.2 · The four GitOps principles (OpenGitOps v1.0, CNCF, 2022)
| Principle | Definition | Implication |
|---|---|---|
| Declarative | The system's desired state is expressed declaratively (what, not how). | Manifests, not scripts. Kustomize, Helm, Terraform HCL all qualify. |
| Versioned & immutable | State is stored such that changes are immutable, with a complete version history. | Git, OCI artefacts. Every state has a SHA. |
| Pulled automatically | Software agents automatically pull the declared state from the source. | Controller-in-cluster, not pipeline-into-cluster. |
| Continuously reconciled | Agents 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
| Dimension | Push CD | GitOps (Pull) |
|---|---|---|
| Credential direction | CI holds cluster creds (outbound) | Cluster holds Git creds (outbound only) |
| Network surface | Inbound to API server | None inbound required |
| Drift | Invisible until next deploy | Detected and auto-healed |
| Audit trail | CI logs (mutable) | git log (immutable) |
| Rollback | Re-run pipeline | git revert |
| Multi-cluster | N×credentials in CI | One 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.
| Controller | CRD | Purpose |
|---|---|---|
| Source | GitRepository, HelmRepository, OCIRepository, Bucket | Pulls and caches source artefacts. |
| Kustomize | Kustomization | Builds and applies Kustomize overlays. |
| Helm | HelmRelease | Installs / upgrades Helm charts declaratively. |
| Notification | Provider, Alert, Receiver | Webhook in/out for events. |
| Image Automation | ImageRepository, ImagePolicy, ImageUpdateAutomation | Scans 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
| Pattern | Layout | Pros / cons |
|---|---|---|
| Single config monorepo | One repo, dirs per app + per env | Easy cross-cuts; can grow huge. |
| App + config repos | App code in one repo; manifests in another | Separation of concerns; coordination overhead. |
| Env-per-branch | dev / stg / prod branches | Familiar; merge conflicts; obscures promotion intent. |
| Env-per-directory (preferred) | overlays/dev, overlays/prod in main | Single source of truth; promotion = PR copy. |
| App-of-apps | Root app references child apps | Bootstrap entire env from one Application. |
| ApplicationSet / Fleet bundle | Templated apps per cluster via generators | Scales 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 bumpsoverlays/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/applydriven by aTerraformCRD. - 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
| Tool | Approach |
|---|---|
| Argo CD ApplicationSet | Generators (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. |
| Karmada | Federation v2 successor; propagate workloads with overrides per cluster. |
| Google Config Sync / Anthos | Hosted 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 theirkubectl editvanishes). - 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.
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
kubectl apply is reverted automatically?