Pods and Deployments
The pod is the smallest unit. A Deployment keeps the right number of pods running and updates them safely.
A Pod is the smallest thing Kubernetes runs. It wraps one or more containers that share the same network address and storage. Most pods have a single container.
CarefulPods are disposable. If a pod dies or its node fails, it is not brought back by itself. You almost never create bare pods in real use.
Deployments
A Deployment declares how many identical pods you want (the replicas) and which container image they run. It creates a ReplicaSet that keeps that number alive, replacing pods that crash.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80The selector and the labels in the template must match. Labels are how Kubernetes connects objects to each other.
Rolling updates
Change the image tag and apply the file again. The Deployment replaces pods a few at a time, so the app stays available. If the new version is bad, you can go back.
kubectl apply -f deployment.yaml
kubectl rollout status deployment/web
kubectl rollout undo deployment/webNoteScale with kubectl scale deployment/web --replicas=5 or by editing replicas in the file. The file is the better source of truth.
Test yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.