Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 37 ยท GitOps Principles

GitOps Principles: The Four Rules Behind Argo CD

Learn the four GitOps principles (declarative, versioned and immutable, pulled automatically, continuously reconciled), what GitOps is not, and how to judge whether a setup is really GitOps.

GitOps is a way of operating systems in which Git holds the desired state and automated software makes reality match it. The term was popularized around 2017 for Kubernetes, and the OpenGitOps working group later wrote the ideas down as four principles. Argo CD is one implementation; Flux is another. Understanding the principles lets you judge any tool, and any pipeline, on its merits.

The code in this lesson is a stand-in: a small scorecard you can run to rate a delivery setup against the four principles. It teaches the ideas; it does not call Argo CD or Kubernetes.

The four principles

Four GitOps principles

Declarative Describe what, not how
Versioned and immutable Every change is a commit
Pulled automatically Agents fetch approved state
Continuously reconciled Software corrects drift

Miss one and it is only partly GitOps.

1 / 2
  1. Declarative. The system's desired state is expressed declaratively: a description of the result, such as "three replicas of this image", rather than a script of steps. Kubernetes YAML, Helm values and Terraform plans are declarative; a Bash script that runs kubectl scale is not.
  2. Versioned and immutable. The desired state is stored in a way that enforces immutability and versioning and retains a complete history. Git does this: commits are content-addressed, every change has an author and a message, and history can be audited.
  3. Pulled automatically. Software agents automatically pull the desired state from the source. Nobody pushes to the cluster; an agent inside (or next to) the cluster fetches approved changes.
  4. Continuously reconciled. Agents continuously observe actual system state and attempt to apply the desired state. Drift is detected and corrected (or at least reported) without a human having to notice.

Why each rule matters

  • Declarative makes a diff possible. You cannot compare "run these five commands" with the live system, but you can compare "replicas: 3" with the live Deployment.
  • Versioned gives you review (pull requests), blame and rollback. Combined with branch protection, production changes require approval.
  • Pulled removes powerful credentials from CI and puts them inside the cluster boundary. It also means the cluster can sit behind a firewall with no inbound access.
  • Reconciled turns the setup into a control loop. A one-time kubectl apply is a deployment; a loop that keeps checking is GitOps.

What GitOps is not

  • Not "we store YAML in Git". If a human still runs kubectl apply from a laptop, only principle two is met.
  • Not "CI runs kubectl". A pipeline that applies on merge is push-based. It can be automated and reviewed, yet it never notices later drift.
  • Not a replacement for CI. Build, test and scan still happen in CI. GitOps starts where CI ends, at the commit that changes desired state.
  • Not only for Kubernetes. The principles apply wherever a declarative API and a reconciler exist (Terraform controllers, Crossplane, cloud config services), though Kubernetes is the best fit.

A typical flow

flowchart LR
  Code["App code change"] --> CI["CI: build, test, scan, push image"]
  CI -->|"commit new image tag"| Config[("Config repo")]
  Config -->|"pull request, review, merge"| Main["main branch"]
  Main -->|"pulled"| Agent["Argo CD"]
  Agent -->|"reconcile"| Cluster["Cluster"]

CI's last step is a Git commit, not a cluster command.

Stand-in: GitOps scorecard

This scorecard rates a setup against the principles. Try the two example setups, then describe your own team's pipeline.

JS Stand-in: GitOps scorecard

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Stand-in: a revertible history

Immutability and history are what make rollbacks trivial: to undo a change you add a new commit that reverses it. The second stand-in models a repository as a list of commits and shows that reverting restores a previous desired state while keeping the full record.

JS Stand-in: revert as a new commit

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The log keeps the bad commit, the revert and the reasons; nothing is rewritten.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which principle is violated when CI runs kubectl apply with production credentials after every merge?

    The pipeline pushes changes. In GitOps an agent pulls them and CI holds no cluster credentials.
  2. 2. Why is a declarative description needed?

    A desired result can be diffed against reality; a list of commands cannot.
  3. 3. A team stores YAML in Git but applies it by hand weekly. How many principles are clearly met?

    Nothing pulls or reconciles, so only declarative and versioned hold.
  4. 4. How do you roll back in a GitOps workflow?

    The desired state lives in Git, so rolling back means changing Git; the agent applies it.

Summary

  • Four principles: declarative, versioned and immutable, pulled automatically, continuously reconciled.
  • Storing YAML in Git, or CI-driven kubectl, is not full GitOps.
  • GitOps starts where CI ends; the handoff is a commit.
  • Rollback is a Git revert; the history stays intact.
  • Argo CD implements pull and reconciliation for Kubernetes.

Next: Repository Layouts for GitOps