In a nutshell: You go from “1 server with docker-compose” to an orchestrator that manages dozens of containers automatically. Kubernetes restarts containers that crash, distributes traffic, and lets you scale with a single command.
Alternative path: This module is optional. The main course path is Modules 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6. Kubernetes is a parallel branch starting from Module 3 (Docker). You don’t need to have completed Modules 5-7 to follow it. If you’re just getting started, focus on the main path and come back here later.
The problem: You have 1 server with docker-compose, it works. But what if you have 50 containers on 10 servers? Who restarts a container that crashes at 3 AM? Who distributes traffic between containers? Who does a deployment with zero downtime?
Kubernetes (K8s) is an orchestrator — a program that coordinates and automatically manages a large number of containers across multiple machines. You tell it “I want 3 copies of my backend running at all times”, and it handles the rest: where to place them, restart them if they crash (self-healing), distribute traffic between them.
The analogies (restaurant):
Pod = a chef at their station
Deployment = “always keep 3 pasta chefs on duty”
Service = the waiter who routes orders to the right chefs
Node = a kitchen (a physical/virtual server)
A chef gets sick? The manager hires a new one automatically.
# 🏄 Done! kubectl is now configured to use "minikube"
# ⚠️ If you're root (or inside a container), minikube refuses the docker driver.
# Add --force:
# minikube start --driver=docker --force
kubectlgetnodes
# NAME STATUS ROLES AGE VERSION
# minikube Ready control-plane 1m v1.x.x
⚠️ STATUS = NotReady right after startup? That’s normal for ~1 minute: the kubelet and the network (CNI) are still initialising. Run kubectl get nodes again a bit later. If it’s still NotReady after 3-4 minutes, run minikube delete then minikube start to start from scratch.
⚠️ RUNTIME_ENABLE error or mount ... fstype: overlay ... invalid argument? You’re inside a container (nested overlay isn’t supported). Use a normal machine/VM.
The basic unit. A pod = one or more containers running together. In practice, 1 pod = 1 container.
Each Kubernetes object is described in YAML with 4 sections: apiVersion (K8s API version), kind (the object type), metadata (name and labels), spec (the configuration).
# pod.yml (you almost never create these directly — you use a Deployment)
apiVersion: v1# Kubernetes API version (v1 = the most basic)
kind: Pod# Object type: a Pod
metadata:
name: mon-backend# The pod name
spec:
containers: # List of containers in this pod (often just 1)
- name: backend
image: mon-user/devops-backend:latest
ports:
- containerPort: 8000# The port the container listens on
Manages a group of identical pods. A replica = a copy of your app. If you want 2 replicas, K8s maintains 2 running copies at all times. If a pod crashes -> it recreates one. If you want 3 replicas -> it maintains 3.
backend-deployment.yml
apiVersion: apps/v1# apps/v1 = the API for Deployments (different from v1 for Pods)
kind: Deployment
metadata:
name: backend
spec: # Deployment spec (how many replicas, how to find them)
replicas: 2# Number of copies of your app to run
selector:
matchLabels:
app: backend# "Find pods that have the label app=backend"
# Must EXACTLY match the labels in the template below
template: # Template for creating each pod
metadata:
labels:
app: backend# This label is used by the selector above to find the pods
spec: # Pod spec (which containers, which ports)
# Note: there are 2 "spec" — the Deployment's and the Pod's
# Option B: if your images are on Docker Hub, K8s downloads them automatically
# (the name in the YAML must match the image on Docker Hub)
⚠️ minikube image load is NOT enough with the :latest tag. Kubernetes then applies imagePullPolicy: Always: it still tries to pull the image from a registry, ignores the locally loaded image and ends up in ImagePullBackOff. That’s why the YAMLs above contain imagePullPolicy: IfNotPresent. The two other solutions: use a versioned tag (:v1) instead of :latest, or push the image to Docker Hub.
# ↑ the "backend" Service carries the DNS name nginx uses (proxy_pass http://backend:8000)
💡 A pod in CrashLoopBackOff with host not found in upstream "backend"? The Service isn’t called backend. The Service name is the internal DNS name: nginx.conf does proxy_pass http://backend:8000, so the Service must be named exactly backend.
The message says “pull access denied”. K8s is trying to download the image from Docker Hub but can’t.
💡 Hint 2
With minikube, local Docker images are not automatically available in the cluster.
✅ Solution
The problem: Kubernetes is trying to download (pull) the image from Docker Hub, but it doesn’t exist on Docker Hub (wrong name, private repo, or image only available locally).
⚠️ The real trap: with the :latest tag, K8s automatically applies imagePullPolicy: Always — it tries to pull the image anyway, even if minikube image load already loaded it into the node. That’s the #1 cause of ImagePullBackOff locally.
The solutions, from the most complete to the simplest:
Declare imagePullPolicy: IfNotPresent in the YAML (the course YAML already contains it):
spec:
containers:
- name: backend
image: mon-user/devops-backend:latest
imagePullPolicy: IfNotPresent# ← use the locally loaded image
Load the local image into minikube (essential if it isn’t on a registry) — in addition to point 1:
Fenêtre de terminal
minikubeimageloadmon-user/devops-backend:latest
Use a versioned tag (:v1 instead of :latest) — that’s the best practice (see above).
Push the image to Docker Hub if you want K8s to actually download it.
Check the image name in the YAML — a typo in image: causes the same error.
After fixing the YAML, re-apply and force K8s to retry:
Fenêtre de terminal
kubectlapply-fbackend.yml
kubectlrolloutrestartdeploymentbackend
⚠️ kubectl rollout restart does NOT fix an ImagePullBackOff if imagePullPolicy stays Always: the pod will retry the pull and fall back into the same state. The YAML is what you need to fix first.
Q: What is Kubernetes?
A: A container orchestrator. It manages deployment, scaling, and high availability of containerized applications on a cluster of machines.
Q: Difference between Docker and Kubernetes?
A: Docker runs ONE container. Kubernetes orchestrates DOZENS/HUNDREDS of containers across multiple machines (scheduling, scaling, self-healing).
Q: What is a Pod?
A: The basic unit in K8s. A pod contains one or more containers that share the same network and storage. In practice, 1 pod = 1 container.
Q: What is a Deployment?
A: An object that manages a group of identical pods. It maintains the desired number of replicas, handles updates (rolling update), and recreates pods that crash.
Q: What is a Service?
A: A stable network access point to a group of pods. Pods have ephemeral IPs, the Service has a fixed IP and distributes traffic.
Q: How does K8s handle a pod that crashes?
A: The Controller detects that the number of replicas no longer matches the desired count, and automatically recreates a pod to compensate (self-healing).
Q: What is a Namespace?
A: A way to isolate resources within a cluster. Useful for separating environments (dev, staging, prod) or teams.
Q: What is an Ingress?
A: A K8s object that manages HTTP(S) routing to Services. It lets you say “requests to api.mysite.com go to the backend Service” and “requests to mysite.com go to the frontend Service”. It’s the HTTP entry point of the cluster.
Q: What is a ConfigMap and a Secret?
A: K8s objects for storing configuration. A ConfigMap stores non-sensitive data (URLs, feature flags). A Secret stores sensitive data (passwords, API keys) encoded in base64. Both are injected into pods as environment variables or files.
Q: What is a liveness probe and a readiness probe?
A: Health checks that K8s runs on your pods. The liveness probe checks if the pod is alive — if it fails, K8s restarts the pod. The readiness probe checks if the pod is ready to receive traffic — if it fails, K8s stops sending requests to it without restarting it.
Q: Difference between ClusterIP, NodePort, and LoadBalancer?
A: Three types of K8s Services. ClusterIP (default) = accessible only from inside the cluster. NodePort = accessible from outside via a port on each node (e.g., node-ip:30080). LoadBalancer = creates an external load balancer (cloud provider) that redirects to the Service. In production, you typically use an Ingress in front of a ClusterIP Service.
Declare resources (CPU/RAM). Without resources.requests and resources.limits, a pod can consume the entire node and crash the others. Always define limits.
Use health checks.readinessProbe (is the pod ready to receive traffic?) and livenessProbe (is the pod still alive?). This is the /api/health endpoint we added in Module 3 (Docker). Without this, K8s sends traffic to pods that aren’t ready.
Never deploy :latest. Tag your images with a commit hash or version number. :latest changes without warning, and you can’t do a clean rollback.
One namespace per environment.dev, staging, prod. This isolates resources and prevents accidentally deleting prod.
Store your YAML in Git. K8s deployment files are code — they should be versioned, reviewed in PRs, and never applied manually in prod.
Image not found (ImagePullBackOff) -> Check the image name in the YAML. If it’s local, minikube image loadandimagePullPolicy: IfNotPresent (otherwise :latest forces a pull).
CrashLoopBackOff -> The container is crash-looping. kubectl logs POD to see the error.
Pending -> Not enough resources on the node. Reduce replicas or resource requests.
Forgetting the selector -> The Service can’t find the pods. Labels in the Deployment must match the Service’s selector.
Ingress: HTTP routing — a single entry point for multiple services, with domain names. This is the first thing you’ll configure to expose your services
Helm: package manager for K8s — you describe your app in a reusable “chart” instead of 10 separate YAML files
Horizontal Pod Autoscaler (HPA): automatically scale the number of pods based on CPU/RAM — essential in production
RBAC: access control in K8s — who has the right to do what in which namespace. More governance than technical