RousselTMLEARNING

Containers

Kubernetes: Pods, ReplicaSets and Deployments (deploying and updating)

Master Kubernetes workloads: anatomy of a pod, ReplicaSet, Deployment, RollingUpdate and Recreate strategies, requests/limits, StatefulSet, DaemonSet and annotated manifests.

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 web

2. Deployment and ReplicaSet #

Replicas and rolling updates.

A complete Deployment #

Hierarchy of Deployment, ReplicaSet and Pods
The Deployment keeps old ReplicaSets to allow rollbacks.
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/web
Common mistake: Never deploy with the latest tag: the same manifest can produce different deployments and rollback becomes impossible. Use versions or digests.

Deployment strategies #

StrategyBehaviorWhen to use it
RollingUpdateReplaces pods progressivelyBy default, without interruption
RecreateDeletes everything, then recreatesApplications that cannot run two versions in parallel
Blue/Green, CanaryThrough Service/Ingress or Argo Rollouts / FlaggerControlled deployments

3. The other controllers #

StatefulSet, DaemonSet, Job.

Choosing the right workload #

WorkloadUseParticularity
DeploymentStateless applicationsInterchangeable pods
StatefulSetDatabases, queuesStable identity (db-0), one volume per pod, ordered startup
DaemonSetAgents (logs, metrics)One pod per node
Job / CronJobFinite or scheduled tasksStops 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

Related articles

Container network security and Kubernetes networking

Secure the container network: how Docker and Kubernetes networking works, CNI, default-deny NetworkPolicies, …

Container registry: choosing and securing your image registry (Docker Hub, Harbor, GHCR, ECR)

Understand container registries: Docker Hub, GitHub Container Registry, cloud registries (ECR, ACR, Artifact …

Kubernetes: architecture and components (control plane, nodes, objects)

Understand the Kubernetes architecture: API server, etcd, scheduler, controller manager, kubelet, kube-proxy,…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!