Skip to main content

HelmRelease


Table of Contents​

  1. Concept
  2. Create a HelmRelease
  3. Values and configuration
  4. Upgrade and Rollback
  5. Helm tests
  6. Hands-on exercises

1 - Concept​

What is a HelmRelease?​

A HelmRelease manages the lifecycle of a Helm chart via GitOps.

Benefits​

BenefitDescription
GitOpsConfiguration in Git
DeclarativeDesired state, not commands
Auto rollbackOn failure
Drift detectionContinuous 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
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):

  1. values from the chart
  2. valuesFrom (in order)
  3. 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

← Previous chapter | Next chapter: Image Automation β†’