Pods, ReplicaSets & Deployments
Docker & Kubernetes for Interviews: lesson 5 of 12
Declare how many and which version; three controllers keep reality matching it.
Lesson 5 of 12 · 7 min
Pods, ReplicaSets & Deployments
Step 1 of 10
You write desired state: a Deployment that wants three replicas of api.
The Idea
A Pod is the smallest thing Kubernetes runs: one or more containers that share a network namespace and storage. Pods are disposable, so you rarely create them yourself. A ReplicaSet keeps a set number of matching Pods running; a Deployment manages ReplicaSets and gives you declarative updates and rollbacks.
Real-World Example
You apply a Deployment with replicas: 3. It creates a ReplicaSet, which creates three Pods. Delete one, or lose its node, and the ReplicaSet makes a replacement — a new Pod with a new UID, not the old one moved.
The Tradeoff
Everything hangs on labels: the selector decides which Pods a ReplicaSet counts, so a careless label can make it adopt Pods it should not. Never edit a Deployment's ReplicaSets by hand; change the Deployment and let its controller reconcile.
Hands-On
# illustrative — kubectl apply -f api.yaml, then kubectl get rs,pods -l app=api
apiVersion: apps/v1
kind: Deployment
metadata: { name: api }
spec:
replicas: 3
selector: { matchLabels: { app: api } }
template:
metadata: { labels: { app: api } }
spec:
containers:
- name: api
image: registry.example.com/api:1.4.2
ports: [{ containerPort: 8000 }]
Your turn
Put the steps in the right order.
- The ReplicaSet creates three Pods from the template
- kubectl apply sends the Deployment to the API server
- The scheduler assigns each Pod to a node
- The Deployment controller creates a ReplicaSet
Mini quiz
1 / 3
Containers in the same Pod can talk to each other over:
Sources
- Pods — Kubernetes Documentation
- ReplicaSet — Kubernetes Documentation
- Deployments — Kubernetes Documentation
- Controllers — Kubernetes Documentation