GitOps architecture
Table of Contents
- Components of a GitOps architecture
- Deployment flow
- Architecture patterns
- Multi-cluster
- High availability
- Hands-on exercises
1 - Components of a GitOps architecture
Overview
Key components
| Component | Role | Examples |
|---|---|---|
| GitOps Controller | Reconciliation | Argo CD, Flux |
| Git Repository | Source of truth | GitHub, GitLab |
| Image Registry | Image storage | Docker Hub, ECR, GCR |
| Secrets Manager | Secrets management | Vault, Sealed Secrets |
| CI Pipeline | Build and tests | GitHub Actions, Jenkins |
The GitOps Controller
🔝 Back to table of contents
2 - Deployment flow
Complete workflow
Detailed steps
# 1. Développeur pousse du code
git push origin feature/new-api
# 2. CI Pipeline se déclenche
- Build de l'application
- Tests unitaires et intégration
- Build de l'image Docker
- Push vers le registry
# 3. CI met à jour le repo GitOps
yq -i '.spec.template.spec.containers[0].image = "myapp:sha123"' \
gitops-repo/apps/myapp/deployment.yaml
git commit && git push
# 4. GitOps Agent détecte le changement
# (ArgoCD/Flux poll toutes les 3 minutes par défaut)
# 5. Agent applique les changements
kubectl apply -f deployment.yaml
# 6. Kubernetes tire l'image et déploie
Repository separation
| Repository | Content | Access |
|---|---|---|
| App Source | Application code | Developers |
| GitOps Config | K8s manifests | Platform team |
| Helm Charts | Shared charts | Platform team |
🔝 Back to table of contents
3 - Architecture patterns
Pattern 1: Monorepo
gitops-monorepo/
├── apps/
│ ├── frontend/
│ ├── backend/
│ └── worker/
├── infrastructure/
│ ├── monitoring/
│ └── ingress/
└── environments/
├── dev/
├── staging/
└── prod/
| Pros | Cons |
|---|---|
| Unified view | Complex permissions |
| Atomic commits | Large repo |
| Clear dependencies | Slower CI/CD |
Pattern 2: Polyrepo
# Repos séparés
org/gitops-apps
org/gitops-infra
org/gitops-monitoring
org/gitops-env-prod
org/gitops-env-staging
| Pros | Cons |
|---|---|
| Fine-grained permissions | Fragmented view |
| Fast CI/CD | Complex coordination |
| Autonomous teams | Possible duplication |
Pattern 3: App of Apps
# apps/root-app.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: root-app
spec:
source:
path: apps
destination:
namespace: argocd
---
# apps/frontend.yaml, backend.yaml, etc.
# Chaque fichier est une Application ArgoCD
🔝 Back to table of contents
4 - Multi-cluster
Hub-spoke architecture
Multi-cluster ArgoCD configuration
# Enregistrer un cluster
apiVersion: v1
kind: Secret
metadata:
name: prod-cluster
labels:
argocd.argoproj.io/secret-type: cluster
type: Opaque
stringData:
name: prod-cluster
server: https://prod-cluster.example.com
config: |
{
"bearerToken": "...",
"tlsClientConfig": {
"insecure": false,
"caData": "..."
}
}
# Application ciblant un cluster spécifique
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: myapp-prod
spec:
destination:
server: https://prod-cluster.example.com
namespace: default
ApplicationSet for multi-cluster
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: myapp
spec:
generators:
- list:
elements:
- cluster: dev
url: https://dev.example.com
- cluster: staging
url: https://staging.example.com
- cluster: prod
url: https://prod.example.com
template:
metadata:
name: 'myapp-{{cluster}}'
spec:
destination:
server: '{{url}}'
namespace: default
source:
path: 'apps/myapp/overlays/{{cluster}}'
🔝 Back to table of contents
5 - High availability
ArgoCD HA
# Installation HA
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/ha/install.yaml
# Composants HA :
# - 3 replicas argocd-server
# - 3 replicas argocd-repo-server
# - 3 replicas argocd-application-controller (avec sharding)
# - Redis HA
Considerations
| Component | HA Strategy |
|---|---|
| Git Repo | Native GitHub/GitLab HA |
| ArgoCD Server | Multiple replicas + LB |
| Controller | Sharding per cluster |
| Redis | Redis Sentinel/Cluster |
Disaster Recovery
# Backup ArgoCD
argocd admin export > backup.yaml
# Restore
argocd admin import < backup.yaml
# Backup Git = le repo lui-même
git clone --mirror [email protected]:org/gitops-repo.git
🔝 Back to table of contents
6 - Hands-on exercises
Quiz
Q1. What are the two types of repositories in a GitOps architecture?
Answer
- App Source Repository: Contains the application code
- GitOps Config Repository: Contains the declarative Kubernetes manifests
Q2. What is the "App of Apps" pattern?
Answer
A "root" ArgoCD Application that deploys other ArgoCD Applications. It allows managing all applications from a single entry point.
Exercise: Architecture design
Design the GitOps architecture for:
- 10 microservices
- 3 environments
- 2 production clusters (for HA)
Suggested solution
gitops-repo/
├── apps/
│ ├── service1/
│ │ ├── base/
│ │ └── overlays/
│ │ ├── dev/
│ │ ├── staging/
│ │ └── prod/
│ └── ... (10 services)
├── infrastructure/
└── applicationsets/
└── all-services.yaml # ApplicationSet pour multi-cluster
Use ApplicationSet to automatically deploy to the 2 production clusters.
🔝 Back to table of contents
Key takeaways
- Components: GitOps Controller, Git Repo, Image Registry, Secrets Manager
- Separate App Source and GitOps Config repos
- Patterns: Monorepo, Polyrepo, App of Apps
- Multi-cluster: Hub-spoke architecture, ApplicationSet
- HA: Replicas, sharding, Redis Sentinel