Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
K8s Workloads Kubernetes Kubernetes: From Zero to Production Module 3 - Pods and Workloads

ReplicaSets - How Kubernetes Maintains Pod Count

Reviewed & accurate
AI Summary

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 3

Self-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  Running
This 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.
Previously: Lesson 14 covered Deployments.
Today: You learned: How K8s maintains the desired Pod count.
Next: Lesson 16 covers DaemonSets.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments