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!
β οΈ 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
π 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


Top comments (0)