Aller au contenu principal

Exercices et projets pratiques


Table des matières

  1. Exercice 1 : Setup ArgoCD
  2. Exercice 2 : Premier déploiement GitOps
  3. Exercice 3 : Multi-environnements
  4. Exercice 4 : Gestion des secrets
  5. Projet final : Pipeline complet
  6. Ressources complémentaires

1 - Exercice 1 : Setup ArgoCD

Objectif

Installer et configurer ArgoCD sur un cluster Kubernetes.

Prérequis

  • Cluster Kubernetes (minikube, kind, ou cloud)
  • kubectl configuré
  • Git repository

Étapes

# 1. Créer le namespace
kubectl create namespace argocd

# 2. Installer ArgoCD
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

# 3. Attendre que les pods soient prêts
kubectl wait --for=condition=Ready pods --all -n argocd --timeout=300s

# 4. Récupérer le mot de passe admin
kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -d && echo

# 5. Port-forward pour accéder à l'UI
kubectl port-forward svc/argocd-server -n argocd 8080:443

# 6. Accéder à https://localhost:8080
# Username: admin
# Password: (récupéré à l'étape 4)

Validation

Checklist de validation
  • Tous les pods ArgoCD sont Running
  • L'UI est accessible
  • Connexion admin réussie
  • Dashboard visible sans erreur

🔝 Retour à la table des matières


2 - Exercice 2 : Premier déploiement GitOps

Objectif

Déployer une application simple via GitOps.

Structure du repo

gitops-exercice/
├── apps/
│ └── hello-world/
│ ├── deployment.yaml
│ └── service.yaml
└── README.md

Fichiers à créer

# apps/hello-world/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
labels:
app: hello-world
spec:
replicas: 2
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: nginx:1.25
ports:
- containerPort: 80
# apps/hello-world/service.yaml
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
selector:
app: hello-world
ports:
- port: 80
targetPort: 80

Créer l'Application ArgoCD

# Appliquer via kubectl ou UI
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: hello-world
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/VOTRE-USER/gitops-exercice.git
targetRevision: HEAD
path: apps/hello-world
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
prune: true
selfHeal: true

Tests

# Vérifier le déploiement
kubectl get deployment hello-world
kubectl get pods -l app=hello-world

# Tester le self-healing
kubectl delete pod -l app=hello-world
# Les pods sont recréés automatiquement

# Tester la réconciliation
kubectl scale deployment hello-world --replicas=5
# ArgoCD rétablit à 2 replicas (comme dans Git)

🔝 Retour à la table des matières


3 - Exercice 3 : Multi-environnements

Objectif

Configurer des déploiements pour dev et prod avec Kustomize.

Structure

gitops-exercice/
└── apps/
└── hello-world/
├── base/
│ ├── kustomization.yaml
│ ├── deployment.yaml
│ └── service.yaml
└── overlays/
├── dev/
│ ├── kustomization.yaml
│ └── namespace.yaml
└── prod/
├── kustomization.yaml
├── namespace.yaml
└── replicas-patch.yaml

Fichiers Kustomize

# base/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- deployment.yaml
- service.yaml

commonLabels:
app: hello-world
# overlays/dev/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: dev

resources:
- ../../base
- namespace.yaml

images:
- name: nginx
newTag: "1.25"
# overlays/dev/namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: dev
# overlays/prod/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: prod

resources:
- ../../base
- namespace.yaml

patches:
- path: replicas-patch.yaml

images:
- name: nginx
newTag: "1.25-alpine"
# overlays/prod/replicas-patch.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 5

Applications ArgoCD

# hello-world-dev
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: hello-world-dev
namespace: argocd
spec:
source:
path: apps/hello-world/overlays/dev
destination:
namespace: dev
---
# hello-world-prod
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: hello-world-prod
namespace: argocd
spec:
source:
path: apps/hello-world/overlays/prod
destination:
namespace: prod

Validation

# Vérifier dev
kubectl get all -n dev
# 2 replicas, nginx:1.25

# Vérifier prod
kubectl get all -n prod
# 5 replicas, nginx:1.25-alpine

🔝 Retour à la table des matières


4 - Exercice 4 : Gestion des secrets

Objectif

Utiliser Sealed Secrets pour gérer les secrets en GitOps.

Installation

# Installer le controller
kubectl apply -f https://github.com/bitnami-labs/sealed-secrets/releases/download/v0.24.0/controller.yaml

# Installer kubeseal
brew install kubeseal # macOS
# ou télécharger depuis GitHub

Créer un Sealed Secret

# 1. Créer le secret en clair (local, ne pas commiter)
kubectl create secret generic db-creds \
--from-literal=username=admin \
--from-literal=password=supersecret123 \
--namespace=prod \
--dry-run=client -o yaml > secret.yaml

# 2. Chiffrer avec kubeseal
kubeseal --format yaml < secret.yaml > sealed-secret.yaml

# 3. Supprimer le secret en clair
rm secret.yaml

# 4. Ajouter le sealed-secret au repo
mv sealed-secret.yaml apps/hello-world/overlays/prod/

Utiliser le secret

# Modifier deployment pour utiliser le secret
spec:
containers:
- name: hello-world
env:
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: db-creds
key: username
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-creds
key: password

Validation

# Le SealedSecret est dans Git ✅
# Le Secret Kubernetes est créé automatiquement
kubectl get secret db-creds -n prod

# Vérifier les valeurs
kubectl get secret db-creds -n prod -o jsonpath='{.data.username}' | base64 -d
# admin

🔝 Retour à la table des matières


5 - Projet final : Pipeline complet

Objectif

Créer un pipeline GitOps complet avec CI/CD, multi-environnements, et secrets.

Architecture

Structure complète

gitops-final/
├── .github/
│ └── workflows/
│ └── validate.yml
├── apps/
│ └── webapp/
│ ├── base/
│ │ ├── kustomization.yaml
│ │ ├── deployment.yaml
│ │ ├── service.yaml
│ │ └── configmap.yaml
│ └── overlays/
│ ├── dev/
│ ├── staging/
│ └── prod/
├── infrastructure/
│ ├── argocd/
│ └── sealed-secrets/
└── README.md

GitHub Actions pour validation

# .github/workflows/validate.yml
name: Validate

on:
pull_request:
paths:
- 'apps/**'

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install tools
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
sudo mv kustomize /usr/local/bin/

- name: Validate YAML
run: |
pip install yamllint
yamllint apps/

- name: Build Kustomize
run: |
for overlay in apps/webapp/overlays/*/; do
echo "Building $overlay"
kustomize build $overlay > /dev/null
done

ApplicationSet

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: webapp
namespace: argocd
spec:
generators:
- list:
elements:
- env: dev
namespace: dev
- env: staging
namespace: staging
- env: prod
namespace: production
template:
metadata:
name: 'webapp-{{env}}'
spec:
project: default
source:
repoURL: https://github.com/VOTRE-USER/gitops-final.git
targetRevision: HEAD
path: 'apps/webapp/overlays/{{env}}'
destination:
server: https://kubernetes.default.svc
namespace: '{{namespace}}'
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true

Livrables attendus

Checklist du projet
  • Repository GitOps structuré
  • Base Kustomize + 3 overlays (dev, staging, prod)
  • GitHub Actions pour validation
  • Sealed Secrets pour les credentials
  • ApplicationSet déployant les 3 environnements
  • README avec documentation
  • Workflow de promotion documenté

🔝 Retour à la table des matières


6 - Ressources complémentaires

Documentation officielle

RessourceLien
ArgoCDhttps://argo-cd.readthedocs.io/
Fluxhttps://fluxcd.io/docs/
Kustomizehttps://kustomize.io/
Sealed Secretshttps://sealed-secrets.netlify.app/

Repos d'exemple

# ArgoCD examples
git clone https://github.com/argoproj/argocd-example-apps

# Flux examples
git clone https://github.com/fluxcd/flux2-kustomize-helm-example

Certifications

  • Certified Kubernetes Administrator (CKA)
  • Certified GitOps Associate (CGOA) - Linux Foundation

Livres recommandés

  • "GitOps and Kubernetes" - Billy Yuen, et al.
  • "Argo CD in Practice" - Livio Zanol Puppato

🔝 Retour à la table des matières


Félicitations !

Vous avez terminé le cours GitOps ! Vous maîtrisez maintenant :

  • ✅ Les principes fondamentaux de GitOps
  • ✅ La différence entre Push et Pull models
  • ✅ L'utilisation d'ArgoCD et/ou Flux
  • ✅ La gestion des secrets en GitOps
  • ✅ Les déploiements multi-environnements
  • ✅ Les bonnes pratiques GitOps

Prochaines étapes

  1. Pratiquer sur des projets personnels
  2. Contribuer à des projets open source
  3. Explorer ArgoCD Rollouts pour les déploiements progressifs
  4. Approfondir avec Argo Events et Argo Workflows

← Retour à la table des matières du cours