🎯 Scenario #8 β€” Deploy a ReplicaSet and Verify Self-Healing of Pods in Kubernetes



This content originally appeared on DEV Community and was authored by Latchu@DevOps

ReplicaSets ensure that the desired number of Pods is always running.

If a Pod is deleted manually β†’ ReplicaSet AUTO-CREATES a new one.

✅ Step 1 β€” Create ReplicaSet YAML

# rs-nginx.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx-rs
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-demo
  template:
    metadata:
      labels:
        app: nginx-demo
    spec:
      containers:
      - name: nginx
        image: nginx:1.25
        ports:
        - containerPort: 80

Apply:

kubectl apply -f rs-nginx.yaml

✅ Step 2 β€” Verify ReplicaSet + Pods

kubectl get rs
kubectl get pods -o wide

You should see 3 Pods with random hash-like suffixes:

nginx-rs-7dd8f995f5-rkzfx
nginx-rs-7dd8f995f5-pxbgl
nginx-rs-7dd8f995f5-7cj2p

✅ Step 3 β€” Test Self-Healing (Delete a Pod)

Pick any one:

kubectl delete pod nginx-rs-7dd8f995f5-rkzfx

Watch Pods:

kubectl get pods -w

Expected behavior:

  • Deleted Pod goes away
  • ReplicaSet automatically creates a NEW pod
  • Count stays at 3 always

Example:

pod "nginx-rs-xxx" deleted
pod "nginx-rs-newxxx" created

🎉 ReplicaSet self-healing verified!

1

⚠ Self-Healing Works Only If Labels Match Selector

If you edit the Pod labels:

kubectl label pod POD_NAME app-

β†’ ReplicaSet stops managing it
β†’ Will create a replacement pod.

🔥 BONUS TEST β€” Scale ReplicaSet

Increase replicas:

kubectl scale rs nginx-rs --replicas=5

Decrease:

kubectl scale rs nginx-rs --replicas=2

2

🌟 Thanks for reading! If this post added value, a like ❤, follow, or share would encourage me to keep creating more content.

β€” Latchu | Senior DevOps & Cloud Engineer

☁ AWS | GCP | ☸ Kubernetes | 🔐 Security | ⚡ Automation
📌 Sharing hands-on guides, best practices & real-world cloud solutions


This content originally appeared on DEV Community and was authored by Latchu@DevOps