5/845 min
Primitives
ReplicaSets β Self-Healing Guarantees
Understand how ReplicaSets maintain a desired pod count and why Deployments exist on top of them.
beginner45 minRead β Lab β Quiz β Practice
π§ Brain Warm-Up
π§ Brain Warm-Up: If a Deployment manages ReplicaSets and a ReplicaSet manages Pods, what happens when you delete a Pod that was created by a Deployment? Who recreates it β the Deployment or the ReplicaSet?
What is a ReplicaSet?
A ReplicaSet ensures a specified number of pod replicas are running at all times. If a pod crashes or is deleted, the ReplicaSet controller immediately creates a replacement.
ReplicaSet (desired: 3) βββ Pod nginx-abc12 β Running βββ Pod nginx-def34 β Running β delete this βββ Pod nginx-ghi56 β Running After deletion: βββ Pod nginx-abc12 β Running βββ Pod nginx-ghi56 β Running βββ Pod nginx-xyz99 β Running (new β RS respawned it)
ReplicaSet vs Deployment
| Feature | ReplicaSet | Deployment |
|---|---|---|
| Maintains desired pod count | β | β (via RS) |
| Rolling updates | β | β |
| Rollback | β | β |
| Revision history | β | β |
You almost never create a ReplicaSet directly. Use a Deployment instead β it creates and manages the ReplicaSet for you, adding rollout and rollback on top.
Selector Must Match Template Labels
The ReplicaSet selector tells it which pods to count. If the selector does not match the pod template labels, the RS will keep creating pods forever (selector finds 0 matching pods).
selector:
matchLabels:
app: nginx # must match β
template:
metadata:
labels:
app: nginx # must match β