Concepts fondamentaux
1 - Les trois grands concepts
| Concept | Description | Analogie |
|---|---|---|
| Chart | Package contenant les templates | Code source |
| Release | Instance d'un chart déployée | Application en production |
| Repository | Collection de charts | npm registry |
2 - Charts en détail
2.1 Qu'est-ce qu'un Chart ?
Un Chart est un bundle de fichiers qui décrit un ensemble de ressources Kubernetes.
wordpress/
├── Chart.yaml # Informations sur le chart
├── Chart.lock # Versions lockées des dépendances
├── values.yaml # Valeurs de configuration par défaut
├── values.schema.json # Schéma JSON des values (optionnel)
├── charts/ # Charts dont ce chart dépend
├── crds/ # Custom Resource Definitions
├── templates/ # Templates + fonctions helpers
│ ├── NOTES.txt # Notes affichées après installation
│ ├── _helpers.tpl # Fonctions helpers partagées
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
│ └── tests/ # Tests du chart
│ └── test-connection.yaml
├── LICENSE # License du chart
└── README.md # Documentation
2.2 Chart.yaml
# Chart.yaml
apiVersion: v2 # API version du chart (v2 pour Helm 3)
name: mon-application # Nom du chart
version: 1.0.0 # Version du chart (SemVer)
appVersion: "2.1.0" # Version de l'application packagée
description: Une application web # Description
type: application # application ou library
# Métadonnées optionnelles
keywords:
- web
- api
home: https://example.com
sources:
- https://github.com/example/repo
maintainers:
- name: John Doe
email: [email protected]
url: https://johndoe.com
icon: https://example.com/icon.png
deprecated: false
kubeVersion: ">=1.20.0" # Versions K8s compatibles
# Annotations personnalisées
annotations:
category: Web Application
licenses: Apache-2.0
# Dépendances
dependencies:
- name: postgresql
version: "12.x.x"
repository: "https://charts.bitnami.com/bitnami"
condition: postgresql.enabled
tags:
- database
- name: redis
version: "17.x.x"
repository: "https://charts.bitnami.com/bitnami"
condition: redis.enabled
2.3 Types de charts
| Type | Description | Utilisation |
|---|---|---|
| application | Déploie des ressources K8s | La plupart des charts |
| library | Fournit des helpers/templates | Charts partagés |
# Chart de type library
apiVersion: v2
name: common-templates
type: library
version: 1.0.0
3 - Releases en détail
3.1 Qu'est-ce qu'une Release ?
Une Release est une instance d'un chart déployée dans le cluster avec une configuration spécifique.
3.2 Stockage des releases
Les informations de release sont stockées dans des Secrets Kubernetes.
# Voir les secrets de release
kubectl get secrets -l owner=helm
# Exemple de secret
# sh.helm.release.v1.my-release.v1
# Structure du nom:
# sh.helm.release.v1.<release-name>.v<revision>
3.3 Cycle de vie d'une release
3.4 Révisions
Chaque opération crée une nouvelle révision :
# Historique des révisions
helm history my-release
# REVISION UPDATED STATUS CHART DESCRIPTION
# 1 Mon Nov 13 10:00:00 2023 superseded nginx-1.0.0 Install complete
# 2 Mon Nov 13 11:00:00 2023 superseded nginx-1.1.0 Upgrade complete
# 3 Mon Nov 13 12:00:00 2023 deployed nginx-1.1.0 Rollback to 2
# Rollback à une révision spécifique
helm rollback my-release 1
4 - Repositories en détail
4.1 Types de repositories
4.2 Repository HTTP classique
Structure d'un repository HTTP :
https://charts.example.com/
├── index.yaml # Index de tous les charts
├── nginx-1.0.0.tgz # Chart packagé
├── nginx-1.1.0.tgz
├── wordpress-5.0.0.tgz
└── wordpress-5.1.0.tgz
# index.yaml
apiVersion: v1
entries:
nginx:
- name: nginx
version: 1.1.0
description: NGINX web server
urls:
- https://charts.example.com/nginx-1.1.0.tgz
created: "2023-11-13T10:00:00Z"
digest: sha256:abc123...
- name: nginx
version: 1.0.0
urls:
- https://charts.example.com/nginx-1.0.0.tgz
generated: "2023-11-13T10:00:00Z"
4.3 OCI Registry
Helm 3 supporte les registries OCI (Open Container Initiative).
# Login à un registry OCI
helm registry login ghcr.io -u username
# Push un chart vers OCI
helm push mychart-1.0.0.tgz oci://ghcr.io/myorg/charts
# Pull depuis OCI
helm pull oci://ghcr.io/myorg/charts/mychart --version 1.0.0
# Installer depuis OCI
helm install myrelease oci://ghcr.io/myorg/charts/mychart --version 1.0.0
4.4 Créer son propre repository
# Avec ChartMuseum (serveur dédié)
docker run -d -p 8080:8080 \
-e STORAGE=local \
-e STORAGE_LOCAL_ROOTDIR=/charts \
-v $(pwd)/charts:/charts \
ghcr.io/helm/chartmuseum:latest
# Avec GitHub Pages
# 1. Créer un repo GitHub
# 2. Packager le chart
helm package ./mon-chart
# 3. Générer l'index
helm repo index . --url https://username.github.io/charts
# 4. Push et activer GitHub Pages
5 - Values en détail
5.1 Hiérarchie des values
Les values peuvent être définies à plusieurs niveaux :
5.2 Fichier values.yaml
# values.yaml
# Configuration de l'image
image:
repository: nginx
tag: "1.25"
pullPolicy: IfNotPresent
# Réplicas
replicaCount: 3
# Service
service:
type: ClusterIP
port: 80
# Ressources
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 100m
memory: 128Mi
# Ingress
ingress:
enabled: false
className: nginx
hosts:
- host: example.local
paths:
- path: /
pathType: Prefix
# Configuration personnalisée
config:
database:
host: localhost
port: 5432
features:
- feature1
- feature2
5.3 Surcharger les values
# Avec un fichier
helm install myapp ./chart -f production.yaml
# Avec plusieurs fichiers (fusion)
helm install myapp ./chart -f base.yaml -f production.yaml
# Avec --set (valeurs simples)
helm install myapp ./chart --set replicaCount=5
# Avec --set (valeurs imbriquées)
helm install myapp ./chart --set image.tag=v2.0.0
# Avec --set (listes)
helm install myapp ./chart --set 'ingress.hosts[0].host=example.com'
# Avec --set-string (forcer le type string)
helm install myapp ./chart --set-string image.tag=1.0
# Avec --set-file (contenu de fichier)
helm install myapp ./chart --set-file config.data=./config.json
# Combinaison
helm install myapp ./chart \
-f base.yaml \
-f production.yaml \
--set replicaCount=10 \
--set image.tag=v2.0.0
5.4 Schéma de validation
// values.schema.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["replicaCount", "image"],
"properties": {
"replicaCount": {
"type": "integer",
"minimum": 1,
"maximum": 10
},
"image": {
"type": "object",
"required": ["repository"],
"properties": {
"repository": {
"type": "string"
},
"tag": {
"type": "string",
"default": "latest"
}
}
},
"service": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["ClusterIP", "NodePort", "LoadBalancer"]
}
}
}
}
}
6 - Relations entre concepts
Résumé
Dans ce chapitre, nous avons approfondi :
- Les Charts : structure, Chart.yaml, types
- Les Releases : cycle de vie, stockage, révisions
- Les Repositories : HTTP, OCI, création
- Les Values : hiérarchie, surcharge, validation
Prochaine étape
Dans le prochain chapitre, nous explorerons en détail l'anatomie d'un Chart.
→ Chapitre suivant : Anatomie d'un Chart