DevopsIntermediate

GitOps Infrastructure: Principles, Tools and Essential Resources

Admin KC
6 min read

TL;DR

A curated reference guide to GitOps for infrastructure: core principles, Flux and ArgoCD, Terraform patterns, and security practices for declarative delivery.

GitOps Infrastructure: Principles, Tools and Essential Resources

Executive Summary

GitOps is one idea with strict consequences: the desired state of your system lives in git, and an automated agent continuously pulls the live system toward it. Done properly, you get an audit trail for every change, rollbacks that are just reverts, and drift that fixes itself. Done halfway — pipelines that still push, secrets pasted into repos, no drift detection — you get the ceremony without the safety. This guide covers the four principles, the Flux versus ArgoCD decision, how Terraform fits, and the practices that keep a GitOps setup trustworthy.

The GitOps loop: Git is the source of truth, the agent closes the gap Commit to Git desired state, reviewed CI tests + builds image published Image tag in Git config repo updated Agent pulls state Argo CD / Flux Cluster reconciled live matches Git Drift corrected self-heal + alert Rollback is a revert, not a redeploy — every state corresponds to a commit.

Why This Matters

Every production incident eventually asks the same question: what changed? In a push-based world the answer is archaeology across CI logs, console clicks, and memory. In a GitOps world the answer is git log. That single property — the environment is a function of a repository — is why GitOps improves both reliability and security: reviewers approve changes before they exist, credentials stay inside the cluster instead of in CI, and a compromised pipeline cannot invent state that git does not describe.

Core Concepts

The Four Principles (OpenGitOps)

  • Declarative — the system is described as desired state, not as steps to execute.
  • Versioned and immutable — the description lives in git; history is the audit log.
  • Pulled automatically — an agent in the environment fetches the desired state; nothing pushes changes in from outside.
  • Continuously reconciled — the agent compares desired and actual state forever, and corrects drift.
  • If any one is missing, you have CI/CD with extra steps. The pull model is the one teams most often skip — and it is the one that removes deploy credentials from your pipeline.

    The GitOps stack — the agent, not the pipeline, touches the cluster Git — versioned desired state, PR review, audit trail CI — build, test, publish image, update the tag in Git Agent — Argo CD / Flux pulls and syncs, prune + self-heal Cluster — live state, namespaces, workloads, overlays Observability — drift alerts, sync status, who changed what CI never touches the cluster — its job ends at recording the image in Git.

    Flux vs ArgoCD

    Both are CNCF-graduated and production-proven. The difference is philosophy:

  • Flux is a toolkit of composable controllers (source, kustomize, helm, notification) that leans into Kubernetes-native patterns and GitOps Toolkit APIs. It shines when you want infrastructure-as-code purity and multi-tenancy built from primitives.
  • ArgoCD is an application-focused platform with a strong UI, first-class multi-cluster management, and an opinionated Application abstraction. It shines when platform teams serve many app teams who want visibility.
  • Pick based on who operates it: infrastructure engineers tend to prefer Flux's composability; platform teams serving developers tend to prefer ArgoCD's UI and app model. Running both is a smell — standardise.

    Terraform in a GitOps World

    Terraform describes infrastructure outside Kubernetes (VPCs, databases, DNS). GitOps discipline still applies: state in a remote backend with locking, plans reviewed on pull requests, applies executed by a controller or a locked pipeline — never from a laptop. Controllers like Flux's terraform-controller (or Crossplane for a fully Kubernetes-native model) close the loop so cloud resources reconcile continuously instead of only when someone runs apply.

    Secrets: The Part Everyone Gets Wrong

    Git is not a secret store, and "the repo is private" is not a control. The working patterns:

  • Sealed Secrets / External Secrets Operator — encrypted or referenced secrets live in git; plaintext exists only inside the cluster.
  • SOPS with age/KMS — encrypt values in place so diffs stay reviewable.
  • Never commit plaintext credentials "temporarily." Git history is forever.
  • Repository Structure

    Two shapes dominate. A monorepo (one repo: apps + infra + clusters) gives atomic changes and one audit trail, at the cost of access control granularity. Repo-per-team/layer scales permissions and blast radius, at the cost of cross-repo coordination. Most organisations land on a hybrid: one platform repo for cluster and shared infrastructure, one repo per team for their applications.

    Decision Framework

    SituationReach for
    Kubernetes apps, platform team serving many devsArgoCD
    Kubernetes infra + apps, controller-purist teamFlux
    Cloud resources (networks, databases)Terraform with reviewed plans, or Crossplane
    Secrets in gitExternal Secrets Operator, Sealed Secrets, or SOPS
    Rollbackgit revert + let reconciliation do the rest — rehearse it

    Should this workload be GitOps? Decide by blast radius, not by fashion How many clusters? and who can change them Many / regulated audit trail required One, small team a few services Prototype / no cluster still finding shape Full GitOps Argo CD + PR review GitOps-lite Flux + Kustomize Plain CI/CD push revisit when it grows If nothing reconciles drift, you have CI/CD with extra repositories.

    Implementation Checklist

  • [ ] Desired state for every environment lives in git — no console-only changes
  • [ ] A reconciliation agent (Flux/ArgoCD) runs in-cluster with least-privilege RBAC
  • [ ] Drift detection on, with alerting when the agent cannot reconcile
  • [ ] Secrets encrypted or externalised; plaintext scan (gitleaks) in CI
  • [ ] Pull requests are the only path to production state; branch protection enforced
  • [ ] Rollback by revert tested in a game day, not assumed
  • [ ] Image updates automated (Renovate/Flux image automation) so git stays the source of truth
  • Trade-offs

    Reconciliation loops add latency: a change lands when the agent polls or receives a webhook, not the instant CI finishes. Git becomes a critical system — an outage or a bad merge affects every environment that trusts it. And the model fits Kubernetes-shaped workloads best; pets, legacy estates, and one-off snowflake systems need adapters or exemptions, which must be explicit rather than silent.

    When Not to Use GitOps

  • Tiny static estates: one server and a deploy script is not improved by a reconciliation controller.
  • Imperative, event-driven systems whose state cannot be described declaratively (some data pipelines, ML training runs) — version the inputs, but do not force the model.
  • Break-glass-heavy environments where operators routinely hand-tune production: fix the culture first, or the agent will spend its life fighting your team.
  • References

    Here are essential resources for learning about GitOps:

  • GitOps Working Group - Official GitOps principles and practices
  • Flux Documentation - Popular GitOps tool for Kubernetes
  • ArgoCD Documentation - Declarative GitOps CD tool
  • WeaveWorks Guide - Original GitOps concept creators
  • GitOps with Terraform - Infrastructure as Code patterns
  • Kubernetes GitOps - K8s management
  • GitHub Actions - GitOps automation
  • GitLab AutoDevOps - Automated GitOps pipelines
  • Cloud Native GitOps - CNCF perspective
  • Security Practices - Google's security guide
  • These resources provide comprehensive information about implementing GitOps practices effectively.

    Why This Matters

    Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.

    Trade-offs to Consider

    Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.

    When NOT to Use This

    Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.

    Decision Framework

    Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.

    Share this articleShare on XShare on LinkedIn

    Keep the decision frameworks coming

    One practical architecture guide a week — patterns, trade-offs, and when not to use them. No spam, unsubscribe anytime.