HelmRelease
Table of Contentsβ
- Concept
- Create a HelmRelease
- Values and configuration
- Upgrade and Rollback
- Helm tests
- Hands-on exercises
1 - Conceptβ
What is a HelmRelease?β
A HelmRelease manages the lifecycle of a Helm chart via GitOps.
Benefitsβ
| Benefit | Description |
|---|---|
| GitOps | Configuration in Git |
| Declarative | Desired state, not commands |
| Auto rollback | On failure |
| Drift detection | Continuous reconciliation |
π Back to table of contentsβ
2 - Create a HelmReleaseβ
From a HelmRepositoryβ
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: nginx
namespace: web
spec:
interval: 5m
chart:
spec:
chart: nginx
version: "15.x"
sourceRef:
kind: HelmRepository
name: bitnami
namespace: flux-system
values:
replicaCount: 3
service:
type: ClusterIP
From a GitRepositoryβ
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: my-app
namespace: default
spec:
interval: 5m
chart:
spec:
chart: ./charts/my-app
sourceRef:
kind: GitRepository
name: my-repo
namespace: flux-system
Via CLIβ
# CrΓ©er le HelmRepository
flux create source helm bitnami \
--url=https://charts.bitnami.com/bitnami \
--interval=1h
# CrΓ©er la HelmRelease
flux create helmrelease nginx \
--source=HelmRepository/bitnami \
--chart=nginx \
--chart-version="15.x" \
--namespace=web \
--create-target-namespace
Recommended structureβ
clusters/my-cluster/
βββ flux-system/
βββ infrastructure/
β βββ sources/
β β βββ bitnami.yaml
β β βββ ingress-nginx.yaml
β βββ releases/
β βββ cert-manager.yaml
β βββ ingress-nginx.yaml
βββ apps/
βββ nginx.yaml
π Back to table of contentsβ
3 - Values and configurationβ
Inline valuesβ
spec:
values:
replicaCount: 3
image:
repository: nginx
tag: "1.25"
service:
type: LoadBalancer
resources:
requests:
memory: 128Mi
cpu: 100m
ValuesFrom (ConfigMap/Secret)β
spec:
valuesFrom:
- kind: ConfigMap
name: nginx-values
valuesKey: values.yaml
- kind: Secret
name: nginx-secrets
valuesKey: secrets.yaml
# ConfigMap avec values
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-values
namespace: web
data:
values.yaml: |
replicaCount: 3
service:
type: ClusterIP
Values mergingβ
The priority order (from lowest to highest):
valuesfrom the chartvaluesFrom(in order)- inline
values
spec:
valuesFrom:
- kind: ConfigMap
name: common-values
- kind: ConfigMap
name: env-specific-values
values:
# Override final
replicaCount: 5
π Back to table of contentsβ
4 - Upgrade and Rollbackβ
Automatic upgradeβ
spec:
chart:
spec:
version: "15.x" # Semver range
# Flux met Γ jour automatiquement vers 15.1, 15.2, etc.
Automatic rollbackβ
spec:
upgrade:
remediation:
remediateLastFailure: true
retries: 3
rollback:
cleanupOnFail: true
Installation with remediationβ
spec:
install:
remediation:
retries: 3
upgrade:
remediation:
retries: 3
remediateLastFailure: true
Suspend a releaseβ
flux suspend helmrelease nginx -n web
# Reprendre
flux resume helmrelease nginx -n web
π Back to table of contentsβ
5 - Helm testsβ
Enable testsβ
spec:
test:
enable: true
timeout: 5m
Ignore test failuresβ
spec:
test:
enable: true
ignoreFailures: true
Post-install hooksβ
spec:
postRenderers:
- kustomize:
patches:
- target:
kind: Deployment
patch: |
- op: add
path: /metadata/labels/managed-by
value: flux
π Back to table of contentsβ
6 - Hands-on exercisesβ
Exercise 1: Deploy nginxβ
# 1. Ajouter le repo Bitnami
flux create source helm bitnami \
--url=https://charts.bitnami.com/bitnami \
--interval=1h
# 2. CrΓ©er le namespace
kubectl create namespace web
# 3. DΓ©ployer nginx
flux create helmrelease nginx \
--source=HelmRepository/bitnami \
--chart=nginx \
--namespace=web \
--values=replicaCount=2
# 4. VΓ©rifier
flux get helmreleases -n web
kubectl get pods -n web
Exercise 2: HelmRelease YAMLβ
# nginx-release.yaml
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: bitnami
namespace: flux-system
spec:
interval: 1h
url: https://charts.bitnami.com/bitnami
---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: nginx
namespace: web
spec:
interval: 5m
chart:
spec:
chart: nginx
version: "15.x"
sourceRef:
kind: HelmRepository
name: bitnami
namespace: flux-system
install:
createNamespace: true
values:
replicaCount: 3
service:
type: ClusterIP
Quizβ
Q1. What is the difference between valuesFrom and values?
Answer
- valuesFrom: Loads values from external ConfigMaps or Secrets
- values: Values defined inline in the HelmRelease
Inline values has the highest priority and overrides valuesFrom.
Q2. How does Flux handle an upgrade failure?
Answer
With remediation:
spec:
upgrade:
remediation:
retries: 3
remediateLastFailure: true
rollback:
cleanupOnFail: true
Flux retries the upgrade, and if it fails, performs an automatic rollback.
π Back to table of contentsβ
Key takeawaysβ
- HelmRelease = Helm chart in GitOps
- Sources: HelmRepository or GitRepository
- inline values or valuesFrom (ConfigMap/Secret)
- Automatic rollback with remediation
- Semver range for automatic upgrades