GitOps Principles (30%)
Notes on gitops principles.
The four principles come from OpenGitOps v1.0.0 (a CNCF GitOps Working Group project). This is the most heavily weighted domain, so know the exact wording and be able to spot which principle a scenario violates.
Topics
- Declarative
- Versioned and Immutable
- Pulled Automatically
- Continuously Reconciled
Declarative
A system managed by GitOps must have its desired state expressed declaratively.
- The entire system is defined declaratively; this is the opposite of imperative configuration.
- Describe what the system should look like, not how to get there
- Separates configuration (desired state) from implementation (commands, API calls, scripts)
- Examples: Kubernetes YAML manifests, Helm charts, Kustomize overlays, Terraform HCL
- Counter-example: a bash script of
kubectl create .../kubectl scale ...commands is imperative, not declarative - Why it matters
- The desired state can be diffed against the live state (you can’t diff a script)
- Reproducible: the same declaration always produces the same result
- Self-documenting: the repo is the description of the system
Versioned and Immutable
Desired state is stored in a way that enforces immutability, versioning and retains a complete version history.
- Applications are stored in a version-controlled SCM and changed through GitOps.
- Every change creates a new version; old versions are never modified in place
- Git does this naturally: commits are content-addressed (SHA), history is append-only (assuming force-push is blocked)
- What this gives you
- Audit trail: who changed what, when, and why (commit author, message, PR review)
- Rollback: return to any previous known-good version (
git revert) - Reproducibility: recreate the system as of any point in history
- Good hygiene that supports this principle
- Branch protection, no force-push to the tracked branch
- Required PR reviews and signed commits
- Pin versions: image digests or immutable tags, chart versions, Git SHAs/tags (avoid
:latest)
Pulled Automatically
Software agents automatically pull the desired state declarations from the source.
- Applications are pulled automatically from SCM.
- An agent (e.g. Argo CD, Flux) running near/in the target system fetches the desired state from the state store
- Pull vs. push
- Push: CI pipeline runs
kubectl apply/helm upgradeagainst the cluster. CI needs cluster credentials. Not GitOps by this principle. - Pull: the agent inside the cluster reads from Git. Cluster credentials never leave the cluster.
- Push: CI pipeline runs
- Benefits of pull
- Smaller attack surface: CI does not need admin creds to production
- Works across firewalls/NAT: only outbound connections from the cluster
- Scales to many clusters: each cluster pulls its own config
- Webhooks are allowed: they notify the agent to pull sooner, but the agent still does the pulling (see Pull vs. Event-driven)
Continuously Reconciled
- Applications must be continuously monitored to ensure compliance with the stored state
Software agents continuously observe actual system state and attempt to apply the desired state.
- The agent runs a control loop forever: observe → diff → act (see State Reconciliation)
- Reconciliation is triggered by divergence, not only by a new commit. If someone runs
kubectl editin the cluster, the agent detects drift and reverts it. - “Continuous” means it keeps happening, not that it is instantaneous (e.g. Argo CD polls every ~3 minutes by default; Flux uses a per-resource
interval) - Tool settings that map to this principle
- Argo CD:
syncPolicy.automatedwithselfHeal: true(revert drift) andprune: true(delete resources removed from Git) - Flux:
Kustomization/HelmReleasespec.interval,prune: true
- Argo CD:
- Manual sync only (no auto-sync) means drift is detected but not corrected — weaker than the principle intends
Quick Reference
| Principle | Keyword | Violated when… |
|---|---|---|
| Declarative | What, not how | Deploys are driven by imperative scripts |
| Versioned and Immutable | History, audit, rollback | Config edited in place, force-pushes, :latest tags |
| Pulled Automatically | Agent pulls | CI pushes to the cluster with stored credentials |
| Continuously Reconciled | Observe → diff → act | Manual changes in the cluster persist; no drift correction |
Self-check
1. A CI pipeline runs helm upgrade against production after tests pass. The chart lives in Git. Which principle is not met?
Answer
Pulled Automatically. The state is declarative and versioned, but it is pushed by CI rather than pulled by an agent.
2. An engineer runs kubectl scale deploy web --replicas=10 and the change persists for days. Which principle is not met?
Answer
Continuously Reconciled. The agent should detect the drift and restore the replica count from Git (e.g. Argo CD selfHeal: true).
3. Why is Git a natural fit for the “Versioned and Immutable” principle?
Answer
Commits are immutable and content-addressed, history is retained, and every change has an author and a message. That gives you an audit trail and easy rollback.