What You Will Learn
Intermediate
- What a ReplicaSet is
- How it relates to Deployments
- Self-healing in action
A ReplicaSet maintains a stable set of Pods at a given count. If a Pod dies, the ReplicaSet creates a new one. Deployments manage ReplicaSets - you rarely create them directly.
Deployment -> ReplicaSet -> Pods
When you create a Deployment, it creates a ReplicaSet. The ReplicaSet creates and maintains Pods. When you update the image, a new ReplicaSet is created.Terminalbash
# See ReplicaSets
kubectl get replicasets
# A Deployment created a ReplicaSet
kubectl describe deployment my-app
# Events: Scaled up replica set my-app-xxx to 3Self-Healing Demo
Terminalbash
# You have 3 Pods
kubectl get pods
# my-app-aaa Running
# my-app-bbb Running
# my-app-ccc Running
# Delete one Pod manually
kubectl delete pod my-app-aaa
# K8s immediately creates a new one!
kubectl get pods
# my-app-aaa Running (NEW - different ID)
# my-app-bbb Running
# my-app-ccc RunningThis is self-healing
You deleted a Pod, and K8s replaced it in seconds. This is the core value of Kubernetes - your app stays running even when containers fail.Practical Exercise
Create a Deployment with 3 replicas
Watch the Pods: kubectl get pods -w
Delete one Pod: kubectl delete pod
Watch: K8s creates a new Pod immediately
Try: delete all 3 - K8s recreates all of them
Key Takeaways
- ReplicaSet maintains a desired number of Pods.
- Deployment creates and manages ReplicaSets.
- If a Pod dies, ReplicaSet creates a new one (self-healing).
- You rarely create ReplicaSets directly - use Deployments.
- Self-healing = K8s always works to match desired state.
Comments
Comments
Post a Comment