Skip to main content
Course/Primitives/ReplicaSets β€” Self-Healing Guarantees
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

FeatureReplicaSetDeployment
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 ↑