Dev.to AI ๐Ÿค– Ai ๐Ÿ‘ 0 ๐Ÿ“– 6 min read

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

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

Docker Mastery

๐Ÿ—๏ธ Terraform Associate Crash Course

Terraform Associate Crash Course

๐Ÿ”€ Git Mastery

Git Mastery

โš™๏ธ DevOps Complete Pack

DevOps Complete Pack

๐Ÿน Mastering Go

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.

๐Ÿ“ฐ Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.