Aller au contenu principal

Gestion des Releases


1 - Cycle de vie d'une release


2 - Installation

2.1 Commande helm install

# Syntaxe de base
helm install [RELEASE_NAME] [CHART] [flags]

# Depuis un repository
helm install my-nginx bitnami/nginx

# Depuis un fichier local
helm install my-app ./my-chart

# Depuis un package
helm install my-app my-chart-1.0.0.tgz

# Depuis une URL
helm install my-app https://example.com/charts/my-chart-1.0.0.tgz

# Depuis OCI
helm install my-app oci://ghcr.io/org/charts/my-chart --version 1.0.0

2.2 Options d'installation

# Namespace
helm install my-app ./chart -n production
helm install my-app ./chart -n production --create-namespace

# Values
helm install my-app ./chart -f values-prod.yaml
helm install my-app ./chart -f base.yaml -f prod.yaml
helm install my-app ./chart --set replicaCount=3
helm install my-app ./chart --set-string version=1.0
helm install my-app ./chart --set-file config=./app.conf

# Version spécifique
helm install my-app bitnami/nginx --version 15.0.0

# Dry-run
helm install my-app ./chart --dry-run
helm install my-app ./chart --dry-run --debug

# Timeout
helm install my-app ./chart --timeout 10m

# Attendre que les ressources soient prêtes
helm install my-app ./chart --wait
helm install my-app ./chart --wait --timeout 5m

# Atomique (rollback auto en cas d'échec)
helm install my-app ./chart --atomic

# Générer un nom automatiquement
helm install ./chart --generate-name
# Résultat: chart-1699891234

2.3 Exemple complet

# Installation production
helm install production-app bitnami/nginx \
--namespace production \
--create-namespace \
--version 15.0.0 \
-f values/base.yaml \
-f values/production.yaml \
--set ingress.enabled=true \
--set ingress.hostname=app.example.com \
--wait \
--timeout 5m \
--atomic

3 - Listing et status

3.1 Lister les releases

# Releases du namespace courant
helm list
helm ls

# Tous les namespaces
helm list --all-namespaces
helm list -A

# Namespace spécifique
helm list -n production

# Filtrer par statut
helm list --deployed
helm list --failed
helm list --pending
helm list --uninstalled # Si --keep-history

# Filtrer par nom
helm list --filter "prod-*"

# Format de sortie
helm list -o json
helm list -o yaml
helm list -o table

3.2 Status d'une release

# Status détaillé
helm status my-app

# Avec révision spécifique
helm status my-app --revision 3

# Afficher les notes seulement
helm status my-app --show-notes

# Format JSON
helm status my-app -o json

3.3 Voir les ressources déployées

# Manifests de la release
helm get manifest my-app

# Values utilisés
helm get values my-app
helm get values my-app --all # Inclure les defaults
helm get values my-app --revision 2

# Notes
helm get notes my-app

# Hooks
helm get hooks my-app

# Tout
helm get all my-app

4 - Mise à jour (Upgrade)

4.1 Commande helm upgrade

# Upgrade basique
helm upgrade my-app ./chart

# Upgrade avec nouvelle version du chart
helm upgrade my-app bitnami/nginx --version 15.1.0

# Upgrade avec nouvelles values
helm upgrade my-app ./chart -f new-values.yaml
helm upgrade my-app ./chart --set replicaCount=5

# Réutiliser les values précédentes
helm upgrade my-app ./chart --reuse-values

# Reset aux values par défaut sauf ceux spécifiés
helm upgrade my-app ./chart --reset-values -f production.yaml

4.2 Options importantes

# Install si n'existe pas (idempotent)
helm upgrade --install my-app ./chart

# Atomique (rollback auto si échec)
helm upgrade my-app ./chart --atomic

# Cleanup en cas d'échec
helm upgrade my-app ./chart --cleanup-on-fail

# Force update (recréer les ressources)
helm upgrade my-app ./chart --force

# Dry-run
helm upgrade my-app ./chart --dry-run

# Diff avant upgrade (plugin helm-diff)
helm diff upgrade my-app ./chart

4.3 Stratégie de mise à jour typique

# 1. Voir les différences
helm diff upgrade my-app ./chart -f production.yaml

# 2. Dry-run
helm upgrade my-app ./chart -f production.yaml --dry-run

# 3. Upgrade avec sécurité
helm upgrade my-app ./chart \
-f production.yaml \
--atomic \
--wait \
--timeout 5m

# 4. Vérifier
helm status my-app
kubectl get pods -l app.kubernetes.io/instance=my-app

5 - Historique et Rollback

5.1 Historique des révisions

# Voir l'historique
helm history my-app

# REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
# 1 Mon Nov 13 10:00:00 2023 superseded my-app-1.0.0 1.0.0 Install complete
# 2 Mon Nov 13 11:00:00 2023 superseded my-app-1.1.0 1.1.0 Upgrade complete
# 3 Mon Nov 13 12:00:00 2023 deployed my-app-1.1.0 1.1.0 Rollback to 2

# Limiter l'historique conservé
helm upgrade my-app ./chart --history-max 10

5.2 Rollback

# Rollback à la révision précédente
helm rollback my-app

# Rollback à une révision spécifique
helm rollback my-app 2

# Rollback avec options
helm rollback my-app 2 --wait --timeout 5m

# Dry-run
helm rollback my-app 2 --dry-run

# Force (recréer les pods)
helm rollback my-app 2 --force

5.3 Comparer des révisions

# Voir les values d'une révision
helm get values my-app --revision 1
helm get values my-app --revision 2

# Différence entre révisions (plugin diff)
helm diff revision my-app 1 2

# Manifest d'une révision
helm get manifest my-app --revision 1

6 - Désinstallation

6.1 Commande helm uninstall

# Désinstaller
helm uninstall my-app

# Garder l'historique
helm uninstall my-app --keep-history

# Désinstaller d'un namespace spécifique
helm uninstall my-app -n production

# Dry-run
helm uninstall my-app --dry-run

# Timeout
helm uninstall my-app --wait --timeout 5m

6.2 Nettoyage complet

# Après uninstall, certaines ressources peuvent rester
# (PVCs, Secrets créés manuellement, etc.)

# Vérifier les ressources restantes
kubectl get all,pvc,secret -l app.kubernetes.io/instance=my-app

# Nettoyage manuel si nécessaire
kubectl delete pvc -l app.kubernetes.io/instance=my-app

7 - Gestion multi-environnements

7.1 Structure de values

values/
├── base.yaml # Configuration commune
├── development.yaml # Overrides dev
├── staging.yaml # Overrides staging
├── production.yaml # Overrides production
└── secrets/
├── dev-secrets.yaml
├── staging-secrets.yaml
└── prod-secrets.yaml

7.2 Exemple de values par environnement

# base.yaml
image:
repository: mon-app
pullPolicy: IfNotPresent

service:
type: ClusterIP
port: 80

resources:
requests:
cpu: 100m
memory: 128Mi

# development.yaml
replicaCount: 1
image:
tag: "dev"
resources:
limits:
cpu: 500m
memory: 512Mi

# production.yaml
replicaCount: 3
image:
tag: "v1.2.3"
resources:
limits:
cpu: 2000m
memory: 2Gi
ingress:
enabled: true
hosts:
- host: app.example.com
autoscaling:
enabled: true
minReplicas: 3
maxReplicas: 10

7.3 Déploiement par environnement

# Development
helm upgrade --install app-dev ./chart \
-n development \
-f values/base.yaml \
-f values/development.yaml

# Staging
helm upgrade --install app-staging ./chart \
-n staging \
-f values/base.yaml \
-f values/staging.yaml

# Production
helm upgrade --install app-prod ./chart \
-n production \
-f values/base.yaml \
-f values/production.yaml \
--atomic \
--wait

8 - Helmfile

8.1 Introduction

Helmfile permet de gérer plusieurs releases de manière déclarative.

# Installation
# macOS
brew install helmfile

# Linux
wget https://github.com/helmfile/helmfile/releases/download/v0.158.0/helmfile_0.158.0_linux_amd64.tar.gz
tar xzf helmfile_*.tar.gz
sudo mv helmfile /usr/local/bin/

8.2 Configuration Helmfile

# helmfile.yaml
repositories:
- name: bitnami
url: https://charts.bitnami.com/bitnami
- name: prometheus-community
url: https://prometheus-community.github.io/helm-charts

environments:
development:
values:
- environments/dev.yaml
production:
values:
- environments/prod.yaml

releases:
- name: nginx
namespace: web
chart: bitnami/nginx
version: 15.0.0
values:
- values/nginx-base.yaml
- values/nginx-{{ .Environment.Name }}.yaml
set:
- name: replicaCount
value: {{ .Values.nginx.replicas | default 1 }}

- name: prometheus
namespace: monitoring
chart: prometheus-community/kube-prometheus-stack
version: 51.0.0
values:
- values/prometheus.yaml
condition: monitoring.enabled

8.3 Commandes Helmfile

# Sync (install/upgrade toutes les releases)
helmfile sync

# Sync pour un environnement
helmfile -e production sync

# Diff avant sync
helmfile diff

# Apply (diff + sync interactif)
helmfile apply

# Status
helmfile status

# Destroy
helmfile destroy

# Template
helmfile template

9 - Bonnes pratiques

9.1 Nommage des releases

# Convention: [env]-[app]-[composant]
helm install prod-myapp-api ./chart -n production
helm install prod-myapp-web ./chart -n production
helm install staging-myapp-api ./chart -n staging

9.2 Labels et annotations

# values.yaml
commonLabels:
team: platform
cost-center: engineering

commonAnnotations:
description: "Application principale"

9.3 Checklist déploiement production

# 1. Vérifier les changes
helm diff upgrade prod-app ./chart -f production.yaml

# 2. Lint le chart
helm lint ./chart

# 3. Template et vérifier
helm template prod-app ./chart -f production.yaml | kubectl apply --dry-run=client -f -

# 4. Déployer avec safeguards
helm upgrade --install prod-app ./chart \
-n production \
-f production.yaml \
--atomic \
--wait \
--timeout 10m

# 5. Vérifier
helm status prod-app
kubectl get pods -n production -l app.kubernetes.io/instance=prod-app

# 6. Tests post-déploiement
helm test prod-app

Résumé

Dans ce chapitre, nous avons maîtrisé :

  • L'installation avec toutes ses options
  • Le listing et status des releases
  • Les upgrades et stratégies de mise à jour
  • L'historique et rollback
  • La désinstallation propre
  • La gestion multi-environnements
  • L'utilisation de Helmfile

Prochaine étape

Dans le prochain chapitre, nous explorerons les Hooks et Tests.

→ Chapitre suivant : Hooks et Tests


← Retour à la table des matières