Back to Articles

GitOps for Infrastructure: Argo CD and Flux

Contents

The GitOps Principles

Strip the tooling away and GitOps is four decisions:

  • Git is the single source of truth. The repository is the record of the environment. The cluster is a cache of it — authoritative about what's running, but never about what should be. If it's not in Git, it doesn't exist, and if it's in the cluster but not in Git, that's an incident, not a configuration.
  • Desired state is declarative. You commit what should exist — manifests, Helm charts, Kustomize overlays — not the steps to get there. The engine figures out the steps; you review the outcome.
  • Reconciliation is continuous. A controller compares Git to live state and converges the two, constantly — not just at deploy time. The loop runs whether or not anyone pressed a button. This is what turns a deploy tool into an operating model.
  • Separation of concerns. Separate repositories for application config, infrastructure (Terraform), and the platform's own GitOps definitions (the Argo CD Applications themselves). Different owners, different review gates, different blast radii.

The fourth principle is the one that makes the first three auditable: the GitOps repo is reviewed by platform engineers, the app repos by the app teams, and the infra repo by the infra team. One merge path per concern, and the merge — not the deploy button — is the control point.

Argo CD[1] vs. Flux[2]

Both are CNCF projects doing the same job — reconcile Git to Kubernetes[3] — and both are actively maintained. The choice is less about capability and more about operational style. Where they genuinely diverge:

Argo CDFlux
User interfaceBuilt-in web UI: diff view, manual sync buttons, per-app history. A real operations surfaceNo UI; kubectl plugins and status. The CLI is the interface
Where the control plane runsOut-of-cluster: a separate set of services that can manage clusters they don't live in. One instance can sync many clustersIn-cluster: the controllers run inside the cluster they manage. One cluster at a time, and the whole loop lives in one place
Core CRDsApplication, ApplicationSet (fleet-level app generation), plus project-based RBACKustomization, HelmRelease, GitRepository, Bucket — one controller per source kind
Sync modelApp-centric: diff, then sync; sync waves and hooks order resources within and across appsSource-centric: poll Git, then apply; ordering via dependsOn between Kustomizations/HelmReleases
Ecosystem fitLarger community, UI-first workflow, multi-cluster from day oneTighter Git integration, batteries-included source kinds, minimal moving parts inside the cluster

The divergence that matters in practice: Argo CD is a control plane that lives outside the clusters it manages — you run it once, point it at many clusters, and the UI is where operations actually happens. Flux is Git automation that lives inside each cluster — there's no second system to run and no central UI, but every cluster carries its own controllers and you operate per-cluster. For a multi-cluster estate, Argo CD's shape is the better fit; for a single cluster where the team lives in kubectl, Flux is lighter. The patterns in the next section are the same on either.

Core Patterns: Apps, Waves, Hooks, Self-Heal

Five patterns do most of the work in a GitOps operation:

  • App-of-apps. A dedicated repo that contains the Argo CD Application definitions (or Flux Kustomizations) for everything. Adding an application is one commit in one repo — the platform team owns the map of the estate, and the map itself is versioned and reviewed.
  • Sync waves. Resources carry a sync-wave annotation (negative waves first, zero default, positive waves after), so migrations run before the app that needs them, and dependents deploy after their dependencies. Without waves, "deploy in order" is a prayer; with waves, it's a property of the sync.
  • Hooks. Resources marked as PreSync/PostSync run as one-shot jobs around the sync — database migrations before, cache warmup after — and are then pruned. Hooks are how you express "this must happen before the new version exists" without baking it into the deploy pipeline.
  • Pruning. With prune enabled, resources deleted from Git are deleted from the cluster. This closes the loop on the source-of-truth claim: the Git repo is the only place a resource may live. Disable pruning and you have a deploy tool, not a control.
  • Self-heal vs. manual sync. Automated sync with selfHeal reverts live drift back to Git on the next reconciliation. Without selfHeal, drift is only detected — the app shows OutOfSync and a human decides. With selfHeal, drift is corrected. The difference is the difference between a detection tool and a control, and it's the single most consequential toggle in the sync policy.

Drift Detection, and What It Means for Audit

Drift detection is the reconciliation loop pointed at the cluster: the controller compares live state to the desired state from Git, periodically (Argo CD's default sync period is three minutes) and on demand (webhooks from the repo, or a manual refresh). Any resource changed by kubectl edit, a direct API call, a failed upgrade that left partial state, or a well-meaning operator shows up as OutOfSync.

For audit, drift events are the record of out-of-band change. In a regulated estate the question is never "what's in Git?" — it's "did anything change the environment without going through Git, who did it, and was it corrected?" Drift detection answers the "did anything" and the "was it corrected"; selfHeal makes the correction automatic rather than a to-do item. Pair the drift log with the commit history and you have a two-sided record: every in-band change has a commit, and every out-of-band change has a drift event.

Rule of Thumb: The drift window — how long a direct cluster change can survive outside Git — depends on the controller, its configured polling and reconciliation intervals, webhook delivery, and whether automatic self-healing is enabled. Measure it in your deployment instead of quoting a product default. If you need a tighter window, shorten the interval or use webhooks; if production requires a human decision, disable automatic healing and page on the OutOfSync state.

A Worked Example: Wiring an Application

Here is the shape of wiring one application in Argo CD — an Application object that lives in the app-of-apps repo — plus the checks that confirm the loop actually works. The labels and value file names are yours; the sync policy is the part that carries the meaning.

# argo/apps/api-gateway.yaml — in the app-of-apps repo
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: api-gateway
  namespace: argocd
  labels:
    app.kubernetes.io/part-of: production
spec:
  project: production
  source:
    repoURL: https://git.example.com/platform/api-gateway.git
    targetRevision: main
    path: deploy/base
    helm:
      valueFiles:
        - values-prod.yaml
  destination:
    server: https://kubernetes.default.svc
    namespace: api-gateway
  syncPolicy:
    automated:
      prune: true      # resources removed from Git leave the cluster
      selfHeal: true   # live drift reverts to Git on the next sync
    syncOptions:
      - CreateNamespace=true
      - PruneLast=true

Three checks confirm the wiring, and they're worth running in this order:

# 1) The Application exists and is Synced / Healthy
kubectl get application api-gateway -n argocd

# 2) Full status: synced revision, per-resource health
kubectl argocd app get api-gateway -o wide

# 3) Prove self-heal: change something live, outside of Git,
#    then watch the next sync period revert it.
kubectl -n api-gateway patch deployment api --type merge \
  -p '{"spec":{"replicas":5}}'
#   ... wait for the sync period, then:
kubectl -n api-gateway get deployment api   # back to the Git value

If the live change sticks after a sync period, selfHeal isn't doing its job — the usual causes are a syncPolicy without automated.selfHeal, or the controller's cluster role lacking permission in the target namespace. The third check is the one teams skip because it takes five minutes; it's also the only one that proves the control works instead of assuming it does.

GitOps Beyond Kubernetes

The GitOps loop — Git as truth, continuous comparison, automatic correction — isn't Kubernetes-specific. Kubernetes just ships the reconciler built in. For the rest of the estate you build the loop from CI and scheduling, and it applies cleanly to the VMware/Windows-heavy side:

TargetRepoReconcilerWhat "drift" means
Terraform (IaaS)Terraform code + stateCI job applies on merge; a PR-based planner (e.g., Atlantis[4]) plans on every PR; a scheduled plan job checks prod stateLive infrastructure vs. what the last apply committed
Ansible (Linux / ESXi hosts)Playbooks + inventory + variablesCI on merge, or agent-based pull on a scheduleHost configuration vs. the committed baseline
Windows baselineWindows config repo (PowerShell DSC or Ansible against Windows)Scheduled run from the repo after reviewServer configuration vs. the committed baseline — where most manual change in a VMware/Windows estate actually happens

The pattern is the same: a reviewed repo, a loop that compares and corrects, and drift that is either auto-fixed or paged. The Windows baseline repo is the piece most estates skip, which is unfortunate because it's where the highest-volume manual change lives — the GPO tweak, the "quick" registry edit, the service that got restarted and never documented. Put it in Git and the whole category of change becomes reviewable.

Security of the Pipeline

GitOps moves the deploy path into Git, so Git becomes the security boundary. The controls that matter:

  • Repo access is prod access. Branch protection on main, required PR review, CODEOWNERS for platform paths. The GitOps repo should be as tightly controlled as the credential store, because a merge to it changes production. If anyone can push to the GitOps repo, the "source of truth" is a source of incident.
  • Separate humans from controllers. The sync controller gets its own identity — a cluster role scoped to the namespaces it manages, not cluster-admin. A controller credential with admin rights is a standing backdoor with a schedule.
  • Image verification at admission. Container images are signed when they're built (cosign/Sigstore), and the cluster checks that signature at the admission step, where a policy engine such as Kyverno[5] or OPA can reject the workload before it starts. This blocks unsigned images and registry-side substitution. It does not make compromised source trustworthy: if an authorized workflow builds malicious code and signs the result, the signature faithfully proves where that bad image came from. Protect the Git review path, bind signatures to an approved workflow and source identity, and verify the image separately at admission.
  • No secrets in the GitOps repo. Secrets come from a runtime secret store (external-secrets, sealed secrets, or the platform's vault integration). A commit that contains a secret is a secret in the permanent record, and the permanent record is the whole point of the repo.

Confirm your tooling versions before you commit to a pattern. The fields of the custom resource definitions (CRDs) these tools install — the Application, Kustomization, and HelmRelease objects you write your YAML against — along with the sync-policy options and the admission-policy schema for Argo CD, Flux, Kyverno, and cosign, all evolve between releases, and the supported Kubernetes versions move with them. The patterns here (sync waves, hooks, selfHeal, verifyImages) are stable across current releases, but the exact schema you write must be checked against the current documentation for the specific versions you'll run — including the version matrix between the GitOps tool and the cluster it manages.

When Not to Adopt GitOps

GitOps is an operating model with real overhead, and there are estates where it's the wrong call:

  1. Small estates. A handful of apps on one cluster, changed a few times a month: kubectl plus a repo you apply from when you change things may be all you need. The reconciliation loop buys value in proportion to the change volume and the surface it covers — below a threshold, you've built a control plane to police a quiet neighborhood.
  2. Teams that aren't Git-fluent. GitOps moves the deploy path into Git. If the team doesn't want to do day-to-day work in Git, you haven't solved the problem — you've relocated it, and now the resistance shows up as direct-to-cluster changes that the reconciler keeps reverting. That's not drift; that's a workflow mismatch wearing a drift badge.
  3. Air-gapped estates without repo replication. Git as source of truth assumes the repo reaches the reconciliation point. If there's no supported path to keep the repo in sync inside the boundary, the "source of truth" lives on the other side of the boundary and the model collapses.
  4. Genuinely imperative changes. Incident mitigation — flip this flag, scale this, cordon that node — is a live change with a record, not a PR. The discipline is to back-fill the change into Git immediately after, so the loop re-converges to a state that includes the mitigation. GitOps doesn't mean everything is a PR; it means nothing stays out of Git.

And the benefit that justifies the overhead when the estate is big enough: every change has a commit, a reviewer, a timestamp, and a rollback path — a revert. In a regulated estate, that chain is the control. Not the tool, not the pipeline — the chain from intent (commit) to approval (review) to effect (sync) to undo (revert), all in one system of record. That's what GitOps is actually for.


References

  1. Argo Project — "Argo CD Documentation": Application and ApplicationSet resources, sync policy, sync waves, hooks, and self-heal. Argo Project Documentation, current.
  2. Flux — "Flux Documentation": Kustomization, HelmRelease, and source kinds, and the controller-based reconciliation model. Flux Documentation, current.
  3. CD Foundation — "GitOps: The Complete Guide": the GitOps principles (source of truth, declarative desired state, continuous reconciliation, separation of concerns). CD Foundation, current.
  4. Atlantis — "Atlantis Documentation": PR-based planning and applying of Terraform from GitHub, and scheduled drift detection. Atlantis Documentation, current.
  5. Kyverno — "Kyverno Documentation": image verification policies and admission control in Kubernetes, including Sigstore/cosign signature checks. Kyverno Documentation, current.
← Back to Articles ← Previous: Python for Infrastructure Automation Next: CI/CD Pipelines for Infrastructure and Configuration →