Skip to main content

Introduction to GitOps


Table of Contents

  1. What is GitOps?
  2. The 4 principles of GitOps
  3. Why adopt GitOps?
  4. Use cases
  5. GitOps and Kubernetes
  6. Hands-on exercises

1 - What is GitOps?

Definition

GitOps is a continuous deployment methodology that uses Git as the single source of truth for declarative infrastructure and applications.

Origin

  • 2017: Term coined by Weaveworks
  • Natural evolution of Infrastructure as Code (IaC)
  • Popularized with the rise of Kubernetes

In one sentence

GitOps = Infrastructure as Code + Pull Request + Continuous Deployment

🔝 Back to table of contents


2 - The 4 principles of GitOps

Principle 1: Declarative

# The desired state is described, not the actions
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3 # Je veux 3 réplicas
# Pas : "scale up de 2 à 3"
ImperativeDeclarative
kubectl scale --replicas=3replicas: 3 in YAML
"Perform this action""Here is the desired state"
Not reproducibleReproducible

Principle 2: Versioned and Immutable

# Tout dans Git
infrastructure/
├── apps/
│ ├── frontend.yaml
│ └── backend.yaml
├── monitoring/
│ └── prometheus.yaml
└── ingress/
└── nginx.yaml

# Historique complet
git log --oneline
a1b2c3d Update replicas to 5
d4e5f6g Add monitoring stack
g7h8i9j Initial infrastructure

Principle 3: Pulled Automatically (Pull)

Principle 4: Continuous Reconciliation

ConceptDescription
Desired stateWhat is in Git
Actual stateWhat is running in the cluster
DriftGap between the two
ReconciliationAutomatic correction

🔝 Back to table of contents


3 - Why adopt GitOps?

Benefits

BenefitDescription
AuditabilityEvery change is tracked in Git
Easy rollbackgit revert = production rollback
SecurityNo direct kubectl in production
ReproducibilitySame config = same result
CollaborationPull Requests for changes
Self-healingAutomatic reconciliation

Concrete example

# Avant GitOps
ssh server
kubectl set image deployment/app app=v2
# Qui a fait quoi ? Quand ? Pourquoi ?

# Avec GitOps
git checkout -b feature/update-app-v2
# Modifier deployment.yaml
git commit -m "Update app to v2 - fixes #123"
git push
# Créer Pull Request
# Review par l'équipe
# Merge = déploiement automatique
# Historique complet dans Git

GitOps ROI

MetricBeforeAfter GitOps
Deployment time30 min5 min
Rollback time1h+2 min
Config incidentsFrequentRare
Audit trailPartial100%

🔝 Back to table of contents


4 - Use cases

Ideal for

  • ✅ Kubernetes deployments
  • ✅ Cloud infrastructure (IaC)
  • ✅ Application configuration
  • ✅ Multi-cluster environments
  • ✅ Distributed teams

Less suited for

  • ⚠️ Legacy non-containerized applications
  • ⚠️ Very frequent changes (databases)
  • ⚠️ Teams without a Git culture

Company examples

CompanyUsage
WeaveworksCoined the term, uses Flux
Intuit2500+ microservices via Argo CD
AdobeMulti-cloud with GitOps
Chick-fil-AEdge computing

🔝 Back to table of contents


5 - GitOps and Kubernetes

Why Kubernetes?

Kubernetes is naturally compatible with GitOps because:

  • Declarative API (YAML/JSON)
  • Controllers concept (reconciliation)
  • Built-in desired state vs actual state

Typical workflow

# 1. Développeur modifie deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 5 # Changement: 3 → 5

# 2. Commit et Push
# git commit -m "Scale my-app to 5 replicas"
# git push

# 3. GitOps operator détecte le changement

# 4. Apply automatique sur le cluster

# 5. Kubernetes réconcilie (crée 2 pods)

GitOps tools for Kubernetes

ToolTypeMaintained by
Argo CDApplicationCNCF
FluxToolkitCNCF
FleetMulti-clusterRancher
Jenkins XCI/CD + GitOpsJenkins

🔝 Back to table of contents


6 - Hands-on exercises

Quiz

Q1. What is the fundamental principle of GitOps?

Answer

Git as the single source of truth for the desired state of the infrastructure.

Q2. What is the difference between the Push and Pull models?

Answer
  • Push: CI/CD pushes changes to the cluster
  • Pull: An agent inside the cluster pulls changes from Git

Q3. Why is Kubernetes suited to GitOps?

Answer

Because Kubernetes has a native declarative API and a controller system that constantly compares the desired state to the actual state.

Exercise: Identify the benefits

For each scenario, identify the GitOps benefit:

  1. An unauthorized change is made directly on the cluster → Self-healing
  2. Need to know who deployed what 3 months ago → Auditability
  3. A deployment causes problems → Easy rollback

🔝 Back to table of contents


Key takeaways

  • GitOps = Git as the source of truth
  • 4 principles: Declarative, Versioned, Pull-based, Reconciliation
  • Benefits: auditability, rollback, security, reproducibility
  • Kubernetes is naturally compatible with GitOps
  • Argo CD and Flux are the most popular tools

🔝 Back to table of contents


Next chapter: GitOps vs CI/CD →