Aller au contenu principal

Exercices et projets pratiques


Table des matières

  1. Exercice 1 : Installation complète
  2. Exercice 2 : Déploiement GitOps
  3. Exercice 3 : Helm avec Flux
  4. Exercice 4 : Image Automation
  5. Projet final : Pipeline GitOps complet
  6. Ressources complémentaires

1 - Exercice 1 : Installation complète

Objectif

Installer Flux et bootstrapper un repository GitOps.

Étapes

# 1. Créer un cluster local
kind create cluster --name flux-workshop

# 2. Vérifier les prérequis
flux check --pre

# 3. Exporter le token GitHub
export GITHUB_TOKEN=<your-token>

# 4. Bootstrap
flux bootstrap github \
--owner=YOUR-USERNAME \
--repository=flux-workshop \
--branch=main \
--path=clusters/demo \
--personal

# 5. Vérifier l'installation
flux check
flux get all

Validation

  • Namespace flux-system créé
  • Tous les controllers Running
  • Repository GitHub créé avec la structure
  • Flux se synchronise lui-même

🔝 Retour à la table des matières


2 - Exercice 2 : Déploiement GitOps

Objectif

Déployer une application avec Kustomization.

Créer la structure

# Dans votre repo flux-workshop
mkdir -p apps/podinfo

# Créer les fichiers
cat > apps/podinfo/namespace.yaml << EOF
apiVersion: v1
kind: Namespace
metadata:
name: podinfo
EOF

cat > apps/podinfo/deployment.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: podinfo
namespace: podinfo
spec:
replicas: 2
selector:
matchLabels:
app: podinfo
template:
metadata:
labels:
app: podinfo
spec:
containers:
- name: podinfo
image: ghcr.io/stefanprodan/podinfo:6.5.0
ports:
- containerPort: 9898
EOF

cat > apps/podinfo/service.yaml << EOF
apiVersion: v1
kind: Service
metadata:
name: podinfo
namespace: podinfo
spec:
selector:
app: podinfo
ports:
- port: 80
targetPort: 9898
EOF

cat > apps/podinfo/kustomization.yaml << EOF
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- namespace.yaml
- deployment.yaml
- service.yaml
EOF

Créer la Kustomization Flux

cat > clusters/demo/podinfo.yaml << EOF
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: podinfo
namespace: flux-system
spec:
interval: 1m
url: https://github.com/YOUR-USERNAME/flux-workshop
ref:
branch: main
---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: podinfo
namespace: flux-system
spec:
interval: 5m
path: ./apps/podinfo
prune: true
sourceRef:
kind: GitRepository
name: podinfo
wait: true
EOF

Déployer

git add .
git commit -m "Add podinfo application"
git push

# Attendre ou forcer
flux reconcile kustomization flux-system --with-source

# Vérifier
kubectl get pods -n podinfo

🔝 Retour à la table des matières


3 - Exercice 3 : Helm avec Flux

Objectif

Déployer un chart Helm via HelmRelease.

Créer les ressources

# clusters/demo/infrastructure/sources/bitnami.yaml
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: bitnami
namespace: flux-system
spec:
interval: 1h
url: https://charts.bitnami.com/bitnami
# clusters/demo/apps/redis.yaml
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: redis
namespace: flux-system
spec:
interval: 5m
chart:
spec:
chart: redis
version: "18.x"
sourceRef:
kind: HelmRepository
name: bitnami
namespace: flux-system
install:
createNamespace: true
targetNamespace: redis
values:
architecture: standalone
auth:
enabled: false
master:
persistence:
enabled: false

Déployer

git add .
git commit -m "Add Redis HelmRelease"
git push

flux reconcile kustomization flux-system --with-source
flux get helmreleases -A
kubectl get pods -n redis

🔝 Retour à la table des matières


4 - Exercice 4 : Image Automation

Objectif

Configurer la mise à jour automatique des images.

Prérequis

# Réinstaller Flux avec les controllers d'image
flux bootstrap github \
--owner=YOUR-USERNAME \
--repository=flux-workshop \
--branch=main \
--path=clusters/demo \
--personal \
--components-extra=image-reflector-controller,image-automation-controller

Créer les ressources

# clusters/demo/image-automation/podinfo-policy.yaml
apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImageRepository
metadata:
name: podinfo
namespace: flux-system
spec:
image: ghcr.io/stefanprodan/podinfo
interval: 1m
---
apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImagePolicy
metadata:
name: podinfo
namespace: flux-system
spec:
imageRepositoryRef:
name: podinfo
policy:
semver:
range: 6.x.x

Modifier le deployment avec marqueur

# apps/podinfo/deployment.yaml
spec:
template:
spec:
containers:
- name: podinfo
image: ghcr.io/stefanprodan/podinfo:6.5.0 # {"$imagepolicy": "flux-system:podinfo"}

Créer l'automation

# clusters/demo/image-automation/automation.yaml
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageUpdateAutomation
metadata:
name: flux-workshop
namespace: flux-system
spec:
interval: 1m
sourceRef:
kind: GitRepository
name: podinfo
git:
checkout:
ref:
branch: main
commit:
author:
email: [email protected]
name: Flux Bot
messageTemplate: 'chore: update image {{range .Updated.Images}}{{.}}{{end}}'
push:
branch: main
update:
path: ./apps
strategy: Setters

Vérifier

flux get images all
# Devrait montrer la dernière version disponible

🔝 Retour à la table des matières


5 - Projet final : Pipeline GitOps complet

Objectif

Créer une stack GitOps complète avec :

  • Multi-environnement (dev, staging, prod)
  • Infrastructure partagée
  • Notifications
  • Secrets avec SOPS

Architecture

Structure du projet

flux-production/
├── clusters/
│ ├── dev/
│ │ ├── flux-system/
│ │ └── apps.yaml
│ ├── staging/
│ │ ├── flux-system/
│ │ └── apps.yaml
│ └── prod/
│ ├── flux-system/
│ └── apps.yaml
├── infrastructure/
│ ├── sources/
│ │ └── bitnami.yaml
│ ├── controllers/
│ │ ├── cert-manager.yaml
│ │ └── ingress-nginx.yaml
│ └── notifications/
│ └── slack.yaml
└── apps/
├── base/
│ └── webapp/
│ ├── deployment.yaml
│ ├── service.yaml
│ └── kustomization.yaml
└── overlays/
├── dev/
│ └── kustomization.yaml
├── staging/
│ └── kustomization.yaml
└── prod/
└── kustomization.yaml

Livrables attendus

  • Repository GitOps structuré
  • 3 environnements configurés
  • Infrastructure partagée (cert-manager, ingress)
  • Application déployée sur les 3 envs
  • Notifications Slack fonctionnelles
  • Documentation README

🔝 Retour à la table des matières


6 - Ressources complémentaires

Documentation officielle

RessourceURL
Flux Docshttps://fluxcd.io/docs/
GitHubhttps://github.com/fluxcd/flux2
Exampleshttps://github.com/fluxcd/flux2-kustomize-helm-example

Outils complémentaires

OutilDescription
Weave GitOpsUI pour Flux
CapacitorUI alternative
SOPSChiffrement des secrets
Sealed SecretsSecrets Kubernetes chiffrés

Communauté

  • Slack CNCF : #flux
  • GitHub Discussions
  • Flux Monthly Meetups

Certifications

  • Certified Kubernetes Administrator (CKA)
  • Certified GitOps Associate (CGOA)

🔝 Retour à la table des matières


Félicitations !

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

  • Installation et bootstrap de Flux
  • Sources Git et Helm
  • Kustomizations et HelmReleases
  • Image Automation pour le CD automatique
  • Notifications et alertes
  • Multi-tenancy et bonnes pratiques

Prochaines étapes

  1. Pratiquer sur des projets personnels
  2. Comparer avec Argo CD selon vos besoins
  3. Explorer Weave GitOps pour l'UI
  4. Contribuer à la communauté Flux

Flux vs Argo CD : Résumé

Pour FluxPour Argo CD
Image Automation nativeUI native excellente
Architecture modulaireTout-en-un simple
CLI-firstVisual-first
Multi-cluster distribuéMulti-cluster centralisé

Les deux sont excellents et CNCF Graduated !


← Retour à la table des matières du cours