ReplicaSet & Deployment
📌 Kubernetes ReplicaSet & Deployment
🔹 What is a ReplicaSet?
A ReplicaSet (RS) is a Kubernetes controller that ensures a specified number of identical Pods are running at all times.
If a Pod:
-
Crashes
-
Is deleted
-
Node goes down
➡️ ReplicaSet automatically creates a new Pod to maintain the desired count.
🔹 Why ReplicaSet is Used
ReplicaSet is used to:
-
Maintain high availability
-
Ensure fault tolerance
-
Automatically heal Pods
-
Run multiple replicas of the same application
🔹 How ReplicaSet Works
-
User defines desired number of replicas
-
ReplicaSet uses labels & selectors
-
It continuously compares:
-
Desired state vs Actual state
-
-
If mismatch occurs → it creates or deletes Pods
🔹 ReplicaSet Key Concepts
1️⃣ Replicas
-
Number of Pod copies to run
-
Defined in
spec.replicas
2️⃣ Pod Template
-
Blueprint for Pods
-
All Pods are identical
-
Defined under
spec.template
3️⃣ Labels & Selectors
-
RS identifies Pods using labels
-
Selector must match Pod labels (mandatory)
⚠️ Mismatch will cause RS to fail
🔹 ReplicaSet YAML Structure (Important)
🔹 What ReplicaSet Can Do
✅ Auto-heal Pods
✅ Scale up/down
✅ Maintain desired state
✅ Load balancing (via Service)
❌ ReplicaSet Limitations (Very Important)
❌ No rolling updates
❌ No rollback support
❌ No version tracking
❌ Updating image requires manual Pod deletion
⚠️ Not recommended for production directly
🔹 When to Use ReplicaSet
-
Rarely used directly
-
Mostly created and managed by Deployments
-
Useful for:
-
Learning Kubernetes basics
-
Understanding controllers
-
🔹 ReplicaSet Summary (Interview-Ready)
ReplicaSet ensures the desired number of Pods are always running using labels and selectors but lacks rolling update and rollback features.
📌 Kubernetes Deployment – Detailed Notes
🔹 What is a Deployment?
A Deployment is a higher-level Kubernetes controller that manages:
-
ReplicaSets
-
Pods
-
Application versions
-
Updates & rollbacks
It is the most commonly used workload in Kubernetes.
🔹 Why Deployment is Used
Deployment is used because it provides:
-
Zero-downtime deployments
-
Rolling updates
-
Easy rollback
-
Version control
-
Production-grade management
👉 Best choice for real-world applications
🔹 How Deployment Works (Flow)
-
Deployment creates a ReplicaSet
-
ReplicaSet creates Pods
-
On update:
-
New ReplicaSet is created
-
Old ReplicaSet is scaled down gradually
-
🔹 Deployment Key Features
1️⃣ Rolling Updates
-
Updates Pods gradually
-
No downtime
-
Default strategy
2️⃣ Rollback
-
Revert to previous version
-
Uses revision history
3️⃣ Versioning
-
Every update creates a new revision
-
Stored in Deployment history
🔹 Deployment YAML Highlights
Changing the image automatically triggers a rollout.
🔹 Deployment Strategies
🔄 RollingUpdate (Default)
-
Gradual replacement
-
Zero downtime
🔁 Recreate
-
Deletes all Pods first
-
Causes downtime
🔹 Deployment Rollout Commands
🔹 Scaling in Deployment
Manual scaling
Auto scaling (HPA)
🔹 What Deployment Can Do
✅ Zero downtime upgrades
✅ Auto healing
✅ Rollback support
✅ Version history
✅ Auto scaling
✅ Production ready
🔹 When to Use Deployment
Use Deployment when:
-
Running stateless applications
-
You need rolling updates
-
You want rollback capability
-
Running apps in production
🔹 ReplicaSet vs Deployment (Key Comparison)
| Feature | ReplicaSet | Deployment |
|---|---|---|
| Auto-heal | ✅ | ✅ |
| Scaling | ✅ | ✅ |
| Rolling update | ❌ | ✅ |
| Rollback | ❌ | ✅ |
| Versioning | ❌ | ✅ |
| Production use | ❌ | ✅ |
Comments
Post a Comment