Deployments
You just saw that a bare Pod, once deleted, stays gone. A Deployment fixes that. You tell it "I want 3 copies of this Pod running at all times," and it relentlessly makes that true - restarting crashed pods, replacing ones on failed nodes, and keeping the count exactly where you asked.
Under the hood, a Deployment manages a ReplicaSet, which in turn manages the Pods:
graph TD
A[Deployment<br/>desired: 3 replicas] --> B[ReplicaSet]
B --> C[Pod]
B --> D[Pod]
B --> E[Pod]
🚀 Create a Deployment
Open k8s/deployment.yaml. Notice three important parts:
replicas: 3- the desired number of Podsselector- how the Deployment knows which Pods belong to it (by the labelapp: web)-
template- the Pod blueprint it stamps out, including areadinessProbeso Kubernetes only sends traffic to pods that are actually ready -
Apply the Deployment:
kubectl apply -f k8s/deployment.yaml -
Watch the pods appear. Run this a few times until all 3 are
RunningandREADY 1/1:kubectl get podsNotice the pod names now have random suffixes like
web-7d9c8b6f5-abc12- the Deployment generated them for you. -
See the Deployment's own view of the world:
kubectl get deployment webREADY 3/3means desired state matches actual state. -
Peek at the ReplicaSet the Deployment created to manage those pods:
kubectl get replicaset
🩹 Watch it heal itself
This is the magic moment. Delete a pod and watch Kubernetes notice and replace it - instantly.
-
Delete exactly one pod (this command grabs the name of the first one for you):
kubectl delete pod $(kubectl get pods -l app=web -o jsonpath='{.items[0].metadata.name}')Tip
You can also copy a specific pod name from
kubectl get podsand runkubectl delete pod <name>yourself. -
Immediately list the pods again:
kubectl get podsYou'll still see 3 pods - one is brand new (check its
AGE), already replacing the one you deleted. The Deployment's reconciliation loop noticed the count dropped to 2 and created a replacement to get back to 3. You never told it to; it just does that. 🩹
🧠The big idea
You declared a desired state ("3 healthy pods running this image") and Kubernetes takes ongoing responsibility for keeping it true. This is what makes Kubernetes resilient - and it's why you'll almost never create bare Pods in real life.
But there's a catch: those 3 pods each have their own IP, and those IPs change every time a pod is replaced. How does anything reliably reach your app? That's the job of a Service - up next. 🔌