🎓 A1Learner
🔍
0 of 51 lessons completed

Kubernetes: GitOps in Brief

GitOps is the idea that Git is the source of truth for the cluster. A tool in the cluster watches Git and makes the cluster match it.

Git holds the truth

The manifests live in Git. The cluster state should match the files in the repo.

git log --oneline -3

The tool watches Git

ArgoCD and Flux both watch the repo. First create a home for ArgoCD, then install it. After the install, kubectl get pods -n argocd lists its pods.

kubectl create namespace argocd

Kustomize patches a base

One base holds the shared YAML. Each environment adds a small overlay on top.

kustomize build overlays/prod

A revert is a deploy

Reverting a commit returns the files to the old state. The tool syncs the old state back in.

git revert HEAD

Example

git log --oneline -3
kustomize build overlays/prod | grep replicas

Key points

  • GitOps: Git holds the desired state, and a tool keeps the cluster matching it
  • Git: the version-control tool that stores the app files and their history.
  • ArgoCD is a GitOps tool that syncs apps from a Git repo into the cluster
  • Flux is a GitOps tool that syncs apps from a Git repo into the cluster
  • Kustomize builds YAML from a base plus small overlays for each environment
  • Helm packages an app as a chart with values, while Kustomize patches plain YAML
  • A Git change is the deploy, because the tool applies it without a human running kubectl
  • A bad Git change is fixed by reverting the commit, because the tool syncs the revert too

In this example, the first command shows the last three commits in the app repo. The second command builds the production overlay. The output shows three replicas in the built YAML, so the repo holds the truth about the cluster.

Note

This lesson teaches the idea only, and building a pipeline belongs to a later course.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

In GitOps, what is the source of truth for the cluster?