Why ReplicaSets

You deployed a bare Pod for your web application. At 3am, it crashed. Nobody noticed. It stayed down until someone checked manually hours later. You restarted it. It crashed again. You restarted it again. This loop has a name: it is called being on-call for a process that should be managing itself. And it does not scale.

The problem is not the crash. Crashes happen. The problem is that nobody was watching and nothing acted. And if the node itself had failed, even a manual restart would have required more intervention.

The Gap in Bare Pods

Let’s make it concrete. Create a bare Pod and then delete it to simulate a crash:

Terminal window
nano bare-pod.yaml
# illustrative only
apiVersion: v1
kind: Pod
metadata:
name: bare-pod
spec:
containers:
- name: web
image: nginx:1.28
Terminal window
kubectl apply -f bare-pod.yaml
kubectl delete pod bare-pod
kubectl get pods

The Pod is gone. Nothing recreated it. That gap, between a Pod dying and a new one appearing, is the gap ReplicaSets fill.

Why is this the default behavior? Kubernetes does not make bare Pods self-healing by design, not by oversight. Not every workload should restart on failure. A database migration that ran successfully should not loop forever. A one-shot batch job is supposed to exit when it finishes. Self-healing is a policy decision, and Kubernetes lets you apply it explicitly through controllers. The Pod is an execution unit. The controller is the policy.

Quiz

Why doesn’t Kubernetes make bare Pods self-healing by default?

Reveal answer

Because the right recovery behavior depends on the workload. A web server should restart forever. A completed batch job should not. By keeping Pods as plain execution units and expressing self-healing through a separate controller (the ReplicaSet), Kubernetes lets you opt in to recovery only where it makes sense.

One Rule, Continuous Enforcement

A ReplicaSet enforces one rule: “there must always be exactly N copies of this Pod running.” It watches all Pods that match its selector and, if the count is off, it acts. Too few: create more. Too many: delete the excess.

dies RS detects count=2creates replacement ReplicaSetdesired: 3 Pod 1Running Pod 2Running Pod 3Running Pod 2 crashes Pod 4(replacement)
dies RS detects count=2creates replacement ReplicaSetdesired: 3 Pod 1Running Pod 2Running Pod 3Running Pod 2 crashes Pod 4(replacement)

Think of a bare Pod as hiring one person for a critical role with no backup plan. When they quit, the role is empty until someone notices and hires again. A ReplicaSet is like a staffing agency with a standing contract: “keep 3 people in this role at all times. If one leaves, hire another immediately.”

The controller does not care why the Pod disappeared. Crash, node failure, accidental deletion: the response is identical. It detects a count below desired and creates a replacement from its Pod template.

Quiz

A Pod belonging to a ReplicaSet with replicas: 3 is manually deleted. What happens next?

  • The Pod count drops to 2 permanently until you manually recreate it
  • The ReplicaSet controller creates a replacement Pod to restore the count to 3
  • The ReplicaSet deletes one more Pod to balance toward 2
Reveal answer

The ReplicaSet controller creates a replacement. It watches the cluster continuously and the moment it sees 2 Pods where it expected 3, it creates a new one from its Pod template. The detection and response happen within seconds.

Both Directions Work

Self-healing handles the “too few” case. But the ReplicaSet also handles “too many.” If a manually created standalone Pod happens to carry labels that match the selector, the ReplicaSet adopts it and counts it toward the total. If that pushes the count above desired, the controller deletes one. This symmetry is intentional: the controller’s job is to make reality match the desired count, whichever direction the gap goes.

The adoption behavior can be surprising. If you have existing Pods with labels that match a new ReplicaSet's selector, the ReplicaSet will adopt them and potentially delete some to reach the desired count. Always double-check your selectors before applying a ReplicaSet to a namespace with existing Pods.

A ReplicaSet is the first self-healing primitive in Kubernetes. It is simpler than a Deployment and more powerful than a bare Pod. In the next lesson, you will write one from scratch, learn the three fields that distinguish it from a Pod manifest, and see the controller act in the simulator.

Get hands-on with Kubernetes

This lesson includes a live terminal with a simulated Kubernetes cluster. Upgrade to Pro to unlock the terminal (free during early access)

Contact us