1. The Pod #
The unit of execution.
Anatomy of a pod #
A pod groups one or more containers that share the same network (one IP) and the same volumes. You almost never create a pod on its own: you go through a controller (Deployment, StatefulSet...) that recreates it if it fails.
apiVersion: v1
kind: Pod
metadata:
name: web
labels: { app: web }
spec:
containers:
- name: nginx
image: nginx:1.27
ports: [{ containerPort: 80 }]
resources:
requests: { cpu: 100m, memory: 128Mi } # réservé pour le scheduling
limits: { cpu: 500m, memory: 256Mi } # plafond (OOMKill si dépassé pour la mémoire)
env:
- { name: APP_ENV, value: prod }kubectl apply -f pod.yaml
kubectl get pod web -o wide
kubectl describe pod web
kubectl delete pod web2. Deployment and ReplicaSet #
Replicas and rolling updates.
A complete Deployment #
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
revisionHistoryLimit: 5
selector:
matchLabels: { app: web }
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # 1 pod de plus que prévu pendant la mise à jour
maxUnavailable: 0 # jamais moins de 3 pods disponibles
template:
metadata:
labels: { app: web }
spec:
containers:
- name: nginx
image: nginx:1.27
readinessProbe: { httpGet: { path: /, port: 80 }, periodSeconds: 5 }
resources:
requests: { cpu: 100m, memory: 128Mi }
limits: { memory: 256Mi }kubectl apply -f deploy.yaml
kubectl rollout status deployment/web
kubectl set image deployment/web nginx=nginx:1.27.2 # déclenche une mise à jour progressive
kubectl get rs -l app=web # ancien et nouveau ReplicaSet
kubectl rollout undo deployment/webCommon mistake: Never deploy with the latest tag: the same manifest can produce different deployments and rollback becomes impossible. Use versions or digests.Deployment strategies #
| Strategy | Behavior | When to use it |
|---|---|---|
| RollingUpdate | Replaces pods progressively | By default, without interruption |
| Recreate | Deletes everything, then recreates | Applications that cannot run two versions in parallel |
| Blue/Green, Canary | Through Service/Ingress or Argo Rollouts / Flagger | Controlled deployments |
3. The other controllers #
StatefulSet, DaemonSet, Job.
Choosing the right workload #
| Workload | Use | Particularity |
|---|---|---|
| Deployment | Stateless applications | Interchangeable pods |
| StatefulSet | Databases, queues | Stable identity (db-0), one volume per pod, ordered startup |
| DaemonSet | Agents (logs, metrics) | One pod per node |
| Job / CronJob | Finite or scheduled tasks | Stops when done |
kubectl create job migration --image=busybox -- sh -c "echo migration; sleep 5"
kubectl create cronjob sauvegarde --image=busybox --schedule="0 2 * * *" -- sh -c "echo backup"
kubectl get jobs,cronjobs
kubectl logs job/migration