GitOps Principles
A deployment model where the desired state lives in Git and an in-cluster agent continuously pulls and reconciles it.
Intermediate · about 3 hours · difficulty 2/5
Learn first: Packaging with Helm and Kustomize, Continuous Integration and Delivery
GitOps applies the infrastructure-as-code idea to deployments: the desired state of every environment is stored in Git, and software agents continuously make reality match it.
The four principles
- Declarative: the whole system is described with manifests, Helm charts or Kustomize overlays.
- Versioned and immutable: that description lives in Git, so every change has an author, a review and a history.
- Pulled automatically: an agent inside the cluster pulls changes; CI no longer needs cluster admin credentials.
- Continuously reconciled: the agent detects drift and corrects it, or at least alerts.
Push CI vs pull GitOps
In push-based CD, the pipeline runs kubectl apply or helm upgrade and needs powerful credentials. In GitOps, CI builds and pushes an image, then updates an image tag in a config repository; the cluster agent does the rest. Rolling back becomes git revert.
Repository layouts
- App repo vs config repo: keep source code and environment manifests separate so deploy history is clean.
- Directory per environment (
envs/dev,envs/prod) with Kustomize overlays or Helm values files. - Promotion is a pull request that copies a version from one environment folder to the next.
- Automated image updaters can open those pull requests for you.
Limits
Secrets need a separate solution, ordering between resources needs care, and non-Kubernetes resources require extra tooling (Crossplane, Terraform controllers).
Good enough to move on: you can explain push vs pull deployment, design an app-plus-config repository layout for three environments, and describe how a rollback works in GitOps.
Key concepts
- OpenGitOps principles
- Push vs pull deployment
- App repo vs config repo
- Environment overlays and promotion
- Drift detection and self-healing
- Image update automation
Mini project
Create a config repository with base manifests and dev and prod Kustomize overlays for a sample app, and write the pull-request flow that promotes a new image tag from dev to prod.
Check yourself
In a GitOps setup, someone runs kubectl edit on a production Deployment. What happens next, and why is that desirable?
Free resources
- OpenGitOps principles (CNCF OpenGitOps)
- Kustomize documentation (Kubernetes SIG CLI)