GitOps Explained: How Kubernetes Deployments Become Fully Automated
You push code to Git. A few minutes later, your application is running in Kubernetes. No manual kubectl apply. No SSH into servers. No copying YAML files. No "Did someone forget to deploy production?" Sounds good,
You push code to Git.
A few minutes later, your application is running in Kubernetes.
No manual kubectl apply.
No SSH into servers.
No copying YAML files.
No "Did someone forget to deploy production?"
Sounds good, right?
This is the idea behind GitOps.
GitOps is one of the most useful concepts to understand if you're learning Kubernetes, DevOps, and cloud engineering.
In this article, we'll break down GitOps from beginner level and build a mental model you can actually use.
๐ค What Is GitOps?
At its simplest:
GitOps means using Git as the source of truth for your infrastructure and application deployment configuration.
Instead of manually telling Kubernetes:
kubectl apply -f deployment.yaml
you commit the desired configuration to Git.
Then an automation system continuously makes the Kubernetes cluster match what's stored in Git.
The basic flow looks like:
Developer
โ
Git Push
โ
Git Repository
โ
GitOps Controller
โ
Kubernetes
โ
Application
That's the foundation.
๐ง The Traditional Deployment Model
Let's imagine a traditional workflow.
A developer creates a new version:
Code
โ
Build
โ
Docker Image
โ
Deploy
Someone might manually run:
kubectl apply -f deployment.yaml
This works.
But problems can appear as the team grows.
Maybe:
Developer A
โ
Changes Kubernetes manually
Developer B
โ
Changes Kubernetes manually
Developer C
โ
Changes Kubernetes manually
Now the actual cluster can become different from what's stored in Git.
That's called configuration drift.
โ ๏ธ What Is Configuration Drift?
Suppose Git says:
replicas: 3
But someone manually changes the cluster:
kubectl scale deployment my-app --replicas=5
Now:
Git:
3 replicas
Cluster:
5 replicas
Which one is correct?
This is the problem GitOps tries to solve.
With GitOps:
Git
โ
Desired State
โ
Controller
โ
Cluster
Git becomes the authoritative record of what the system should look like.
๐ฅ The GitOps Mental Model
Think of GitOps as:
Git = Desired State
Kubernetes:
Cluster = Current State
The GitOps controller continuously compares them.
Git
โ
โ Desired State
โผ
โโโโโโโโโโโโโโโ
โ GitOps โ
โ Controller โ
โโโโโโโโฌโโโโโโโ
โ
โ Reconcile
โผ
Kubernetes
โ
โ
โผ
Application
If the cluster doesn't match Git, the controller can work toward the desired state.
This is the reconciliation model.
๐ What Does Reconciliation Mean?
This word is extremely important.
Imagine Git says:
replicas = 3
but Kubernetes currently has:
replicas = 2
The GitOps controller notices the difference.
It works toward:
2 โ 3
Now suppose someone manually changes the cluster:
3 โ 5
The controller can detect the difference between:
Desired: 3
Current: 5
and reconcile the cluster back toward the declared state, depending on the controller's configuration.
This is one of the fundamental ideas behind GitOps.
๐๏ธ GitOps Architecture
A typical setup might look like this:
Developer
โ
โผ
Git Repository
โ
โผ
GitOps Controller
โ
โผ
Kubernetes API
โ
โโโโโโโโโโโโผโโโโโโโโโโโ
โผ โผ โผ
Pod Pod Pod
โ โ โ
โโโโโโโโโโโโผโโโโโโโโโโโ
โผ
Application
The Git repository might contain:
k8s/
โโโ deployment.yaml
โโโ service.yaml
โโโ ingress.yaml
โโโ configmap.yaml
Or you might use:
Helm
or:
Kustomize
to manage Kubernetes configuration.
๐งฉ Where Argo CD Comes In
One popular GitOps tool is Argo CD.
The basic concept is:
Git Repository
โ
Argo CD
โ
Kubernetes
Argo CD watches your Git repository and compares the desired configuration with the Kubernetes cluster.
You can see the state of your applications through its UI and CLI.
This gives teams visibility into:
- Application health
- Sync status
- Deployment history
- Configuration differences
- Kubernetes resources
๐ A Simple Example
Suppose your Git repository contains:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.27
You commit:
git add .
git commit -m "Deploy nginx"
git push
Your GitOps controller sees the change.
Then:
Git
โ
New Desired State
โ
GitOps Controller
โ
Kubernetes
โ
3 NGINX Pods
You don't need to manually run kubectl apply.
๐ณ What About Docker?
GitOps doesn't replace Docker.
Docker and Kubernetes still have their jobs.
A typical workflow might be:
Source Code
โ
Docker Build
โ
Docker Image
โ
Container Registry
โ
Git Update
โ
GitOps Controller
โ
Kubernetes
For example:
myapp:1.0
becomes:
myapp:1.1
Your deployment configuration is updated in Git.
The GitOps system detects the change and deploys it.
๐ง GitOps + CI/CD
This is where things become really interesting.
A modern pipeline might look like:
Developer
โ
Git Push
โ
CI
โโโ Test
โโโ Build
โโโ Security Scan
โโโ Push Docker Image
โ
Update Deployment
โ
Git
โ
Argo CD
โ
Kubernetes
Notice something important:
CI builds and validates the software.
GitOps handles deployment based on the desired state.
They can work together.
๐ Traditional CI/CD vs GitOps
Traditional approach:
CI Pipeline
โ
kubectl apply
โ
Kubernetes
GitOps approach:
CI Pipeline
โ
Update Git
โ
GitOps Controller
โ
Kubernetes
The second approach creates a clearer separation between:
Build
and:
Deployment
๐ How Should You Structure the Repository?
There isn't one universal structure, but a simple example could be:
gitops-repo/
โ
โโโ apps/
โ โโโ frontend/
โ โ โโโ deployment.yaml
โ โ โโโ service.yaml
โ โ
โ โโโ backend/
โ โโโ deployment.yaml
โ โโโ service.yaml
โ
โโโ infrastructure/
โ โโโ ingress/
โ โโโ monitoring/
โ
โโโ environments/
โโโ dev/
โโโ staging/
โโโ production/
For larger systems, teams may use Helm or Kustomize to avoid duplicating configuration.
The important principle is:
Make the desired state understandable and version controlled.
๐ Multiple Environments
Imagine:
Development
Staging
Production
You could have different configurations.
For example:
environments/
โโโ dev/
โโโ staging/
โโโ production/
Development:
replicas: 1
Staging:
replicas: 2
Production:
replicas: 5
Git records the desired configuration for each environment.
๐ Why GitOps Is Powerful for Auditing
Imagine someone asks:
"Who changed production?"
With Git-based deployment configuration, you can inspect:
Commit
Author
Timestamp
Changed files
Pull request
Review
Instead of:
"Someone logged into the cluster last night."
That traceability can be extremely valuable.
๐ก๏ธ GitOps and Security
GitOps can also support stronger deployment controls.
For example:
Developer
โ
Pull Request
โ
Code Review
โ
Approval
โ
Merge
โ
GitOps Deployment
Instead of giving every developer direct production access, you can reduce the need for manual cluster changes.
But GitOps isn't automatically secure.
You still need to protect:
- Git repositories
- CI/CD systems
- Kubernetes credentials
- Secrets
- GitOps controllers
- Container images
Security remains an engineering responsibility.
๐ฆ GitOps + Helm
Remember Helm?
You can combine Helm and GitOps.
For example:
Git
โ
โโโ Helm Chart
โ
โโโ Values
โ
Argo CD
โ
Kubernetes
Your Git repository can contain:
my-app/
โโโ Chart.yaml
โโโ values.yaml
โโโ templates/
And Argo CD can use that configuration to deploy the application.
This is a very common pattern to understand when moving deeper into Kubernetes.
๐งฑ GitOps + Kustomize
Another option is Kustomize.
For example:
base/
โโโ deployment.yaml
โโโ service.yaml
overlays/
โโโ dev/
โโโ staging/
โโโ production/
The base configuration can be reused while environment-specific overlays customize it.
Again, the goal is:
Reusable Configuration
+
Environment Differences
+
Git Version Control
๐งช Build Your Own GitOps Project
If you're learning DevOps, don't just install Argo CD and stop there.
Build a complete project.
Project: GitOps Kubernetes Deployment Platform
Architecture:
GitHub
โ
โผ
Git Repository
โ
โโโโโโโดโโโโโโ
โ โ
โผ โผ
Helm Config
โ โ
โโโโโโโฌโโโโโโ
โผ
Argo CD
โ
โผ
Kubernetes
โ
โโโโโโโโโโผโโโโโโโโโ
โผ โผ โผ
Frontend Backend Database
Then add:
โ Docker
โ Kubernetes
โ Helm
โ Argo CD
โ GitHub Actions
โ Prometheus
โ Grafana
โ Trivy
Now you have a project that demonstrates several real DevOps concepts together.
๐ฏ A Practical GitOps Learning Path
If you're starting from zero:
Linux
โ
Git
โ
Docker
โ
Kubernetes
โ
YAML
โ
Helm
โ
CI/CD
โ
Argo CD
โ
GitOps
โ
Monitoring
โ
Security
Don't jump directly into Argo CD without understanding Kubernetes.
Otherwise you'll end up learning:
"Click this button"
instead of understanding:
"Why does this deployment happen?"
๐ง The Biggest Lesson
GitOps isn't really about Argo CD.
It isn't really about Helm.
It isn't even really about Git.
The deeper idea is:
Declare the state you want, store it in a version-controlled system, and continuously reconcile the actual system toward that desired state.
That's a powerful engineering model.
Desired State
โ
Version Control
โ
Reconciliation
โ
Actual State
Once you understand that, tools become easier to learn.
๐ Want to Learn Kubernetes Properly?
If you're learning Kubernetes and preparing for the Certified Kubernetes Administrator (CKA), I've created:
CKA Complete Study Guide โ Certified Kubernetes Administrator
It is designed as a structured resource for learning Kubernetes concepts, administration, troubleshooting, and practical skills.
๐ Get the CKA Complete Study Guide
You can combine the book with hands-on labs:
Read
โ
Build
โ
Deploy
โ
Break
โ
Troubleshoot
โ
Automate
๐ ๏ธ More DevOps Learning Resources
๐ณ Docker Mastery
๐๏ธ Terraform Associate Crash Course
Terraform Associate Crash Course
๐ Git Mastery
โ๏ธ DevOps Complete Pack
๐น Mastering Go
Final Thoughts
The first time you see GitOps, it can feel like another complicated DevOps buzzword.
But the core idea is actually simple:
You define what you want.
โ
You store it in Git.
โ
Automation observes it.
โ
Kubernetes is reconciled.
Instead of asking:
"How do I manually deploy this?"
you start asking:
"What should the desired state be?"
That shift in thinking is one of the most important steps from learning Kubernetes โ thinking like a DevOps engineer.
And once you combine:
Git
+
Docker
+
Kubernetes
+
Helm
+
CI/CD
+
Argo CD
you start getting a real picture of how modern cloud-native deployment workflows fit together.
Don't just learn GitOps. Build a system where Git is actually responsible for deploying your application.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.