Introduction to GitOps
Table of Contents
- What is GitOps?
- The 4 principles of GitOps
- Why adopt GitOps?
- Use cases
- GitOps and Kubernetes
- 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"
| Imperative | Declarative |
|---|---|
kubectl scale --replicas=3 | replicas: 3 in YAML |
| "Perform this action" | "Here is the desired state" |
| Not reproducible | Reproducible |
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
| Concept | Description |
|---|---|
| Desired state | What is in Git |
| Actual state | What is running in the cluster |
| Drift | Gap between the two |
| Reconciliation | Automatic correction |
🔝 Back to table of contents
3 - Why adopt GitOps?
Benefits
| Benefit | Description |
|---|---|
| Auditability | Every change is tracked in Git |
| Easy rollback | git revert = production rollback |
| Security | No direct kubectl in production |
| Reproducibility | Same config = same result |
| Collaboration | Pull Requests for changes |
| Self-healing | Automatic 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
| Metric | Before | After GitOps |
|---|---|---|
| Deployment time | 30 min | 5 min |
| Rollback time | 1h+ | 2 min |
| Config incidents | Frequent | Rare |
| Audit trail | Partial | 100% |
🔝 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
| Company | Usage |
|---|---|
| Weaveworks | Coined the term, uses Flux |
| Intuit | 2500+ microservices via Argo CD |
| Adobe | Multi-cloud with GitOps |
| Chick-fil-A | Edge 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
| Tool | Type | Maintained by |
|---|---|---|
| Argo CD | Application | CNCF |
| Flux | Toolkit | CNCF |
| Fleet | Multi-cluster | Rancher |
| Jenkins X | CI/CD + GitOps | Jenkins |
🔝 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:
- An unauthorized change is made directly on the cluster → Self-healing
- Need to know who deployed what 3 months ago → Auditability
- 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