What Is GitOps? (Pull vs Push)
How GitOps uses a declarative Git repository as the single source of truth and an in-cluster pull agent to converge cluster state.
TL;DR
GitOps makes a declarative Git repository the single source of truth for infrastructure and apps. Instead of CI pushing kubectl apply with cluster-admin keys, an in-cluster pull agent (Argo CD or Flux) watches Git and continuously converges the cluster to match.
Intent
Understand the four OpenGitOps principles and why pull-based reconciliation beats ad-hoc kubectl apply scripts from CI runners.
Problem
In traditional push-based CD, your CI pipeline builds an image, logs into the cluster with a kubeconfig secret, and runs kubectl apply or helm upgrade. That creates two risks: CI holds powerful cluster credentials, and once the CI job finishes, nobody notices if someone manually edits the cluster later.
Solution
The OpenGitOps standard defines four principles:
- Declarative: The desired state of the system is expressed declaratively (Kubernetes YAML, Helm values, Kustomize).
- Versioned and Immutable: Desired state is stored in Git with full commit history, PR reviews, and
git revertrollbacks. - Pulled Automatically: Software agents inside the cluster (Argo CD or Flux) automatically pull desired state declarations from Git.
- Continuously Reconciled: Agents observe actual cluster state and continuously apply changes whenever actual state diverges from Git.
Real-world analogy
▶ Flow: watch it work
GitOps Pull Loop: Commit → Detect → Sync → Cluster == Git
Press Start or tap any step dot to trace the path.
▸All steps (7)
Code
An Argo CD Application manifest declaring which Git repo and path to reconcile into the cluster:
# Declarative Argo CD Application (not run — requires Argo CD installed in cluster)
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: web-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/example/k8s-config.git
targetRevision: main
path: apps/web
destination:
server: https://kubernetes.default.svc
namespace: production
syncPolicy:
automated:
prune: true
selfHeal: trueWhen to use / when to avoid
- You run Kubernetes clusters and want auditable, PR-reviewed deployments with easy git revert rollbacks.
- You want to remove cluster-admin kubeconfig secrets from external CI runners.
- You are deploying a single static site to a managed host (a simple CI deploy step is lighter than running Argo CD or Flux).
- Your team still relies on imperative hotfixes via kubectl edit without committing back to Git.
How to implement
Separate app code and config (or use a dedicated config path)
Keep declarative Kubernetes manifests in a tracked Git branch.
Install Argo CD or Flux in the cluster
Grant the in-cluster controller read-only access (deploy key or GitHub App) to your config repo.
Point an Application or Kustomization at the repo
Enable automated sync and selfHeal once your manifests are tested in CI.
Pros / Cons
- Least privilege: CI never needs direct write credentials to production Kubernetes.
- Audit trail and instant rollback via Git history and PR reviews.
- Adds an in-cluster controller to operate, monitor, and upgrade.
- Secrets cannot be committed in plaintext—requires Sealed Secrets, SOPS, or External Secrets Operator.
Relations
Check yourself
Check Yourself
1. How does pull-based GitOps reduce the blast radius of a compromised CI runner?
2. In GitOps, how should you roll back a broken Kubernetes config change?
Sources
Related Notes
CI/CD for This Site
How Mengty Learns validates the Next.js static build, tests hands-on labs, and collects weekly RSS inbox items using three GitHub Actions workflows.
Drift and Reconciliation
What configuration drift is, how GitOps agents detect OutOfSync resources, and how automated reconciliation heals the cluster.