Skip to main content

Hands-on exercises and projects


Table of Contents

  1. Exercise 1: Complete installation
  2. Exercise 2: GitOps deployment
  3. Exercise 3: Helm with Flux
  4. Exercise 4: Image Automation
  5. Final project: Complete GitOps pipeline
  6. 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

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

Complementary tools

ToolDescription
Weave GitOpsUI for Flux
CapacitorAlternative UI
SOPSSecrets encryption
Sealed SecretsEncrypted 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

  1. Practice on personal projects
  2. Compare with Argo CD based on your needs
  3. Explore Weave GitOps for the UI
  4. Contribute to the Flux community

Flux vs Argo CD: Summary

For FluxFor Argo CD
Native Image AutomationExcellent native UI
Modular architectureSimple all-in-one
CLI-firstVisual-first
Distributed multi-clusterCentralized multi-cluster

Both are excellent and CNCF Graduated!


← Back to the course table of contents