Hands-on exercises and projects
Table of Contents
- Exercise 1: Complete installation
- Exercise 2: GitOps deployment
- Exercise 3: Helm with Flux
- Exercise 4: Image Automation
- Final project: Complete GitOps pipeline
- Additional resources
1 - Exercise 1: Complete installation
Objective
Install Flux and bootstrap a GitOps repository.
Steps
# 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
- flux-system namespace created
- All controllers Running
- GitHub repository created with the structure
- Flux synchronizes itself
🔝 Back to table of contents
2 - Exercise 2: GitOps deployment
Objective
Deploy an application with a Kustomization.
Create the 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
Create the Flux Kustomization
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
Deploy
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
🔝 Back to table of contents
3 - Exercise 3: Helm with Flux
Objective
Deploy a Helm chart via HelmRelease.
Create the resources
# 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
Deploy
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
🔝 Back to table of contents
4 - Exercise 4: Image Automation
Objective
Configure automatic image updates.
Prerequisites
# 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
Create the resources
# 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
Modify the deployment with a marker
# apps/podinfo/deployment.yaml
spec:
template:
spec:
containers:
- name: podinfo
image: ghcr.io/stefanprodan/podinfo:6.5.0 # {"$imagepolicy": "flux-system:podinfo"}
Create the 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
Verify
flux get images all
# Devrait montrer la dernière version disponible
🔝 Back to table of contents
5 - Final project: Complete GitOps pipeline
Objective
Create a complete GitOps stack with:
- Multi-environment (dev, staging, prod)
- Shared infrastructure
- Notifications
- Secrets with SOPS
Architecture
Project structure
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
Expected deliverables
- Structured GitOps repository
- 3 environments configured
- Shared infrastructure (cert-manager, ingress)
- Application deployed to the 3 envs
- Working Slack notifications
- README documentation
🔝 Back to table of contents
6 - Additional resources
Official documentation
| Resource | URL |
|---|---|
| Flux Docs | https://fluxcd.io/docs/ |
| GitHub | https://github.com/fluxcd/flux2 |
| Examples | https://github.com/fluxcd/flux2-kustomize-helm-example |
Complementary tools
| Tool | Description |
|---|---|
| Weave GitOps | UI for Flux |
| Capacitor | Alternative UI |
| SOPS | Secrets encryption |
| Sealed Secrets | Encrypted Kubernetes secrets |
Community
- CNCF Slack: #flux
- GitHub Discussions
- Flux Monthly Meetups
Certifications
- Certified Kubernetes Administrator (CKA)
- Certified GitOps Associate (CGOA)
🔝 Back to table of contents
Congratulations!
You have completed the Flux CD course! You now master:
- Installation and bootstrap of Flux
- Git and Helm sources
- Kustomizations and HelmReleases
- Image Automation for automatic CD
- Notifications and alerts
- Multi-tenancy and best practices
Next steps
- Practice on personal projects
- Compare with Argo CD based on your needs
- Explore Weave GitOps for the UI
- Contribute to the Flux community
Flux vs Argo CD: Summary
| For Flux | For Argo CD |
|---|---|
| Native Image Automation | Excellent native UI |
| Modular architecture | Simple all-in-one |
| CLI-first | Visual-first |
| Distributed multi-cluster | Centralized multi-cluster |
Both are excellent and CNCF Graduated!