Day 4: Deployments & ReplicaSets — How Kubernetes Runs and Manages Your App
Let’s Begin With What You Might Know
So far, we’ve talked about:
- How Kubernetes runs containers inside Pods
- How those Pods live on Nodes inside a Cluster
- And how the Control Plane decides what happens where
Now imagine this:
You’ve built a great app.
You package it into a container, wrap it in a Pod, and launch it withkubectl run
.
Awesome — it's up and running! But soon, you’ll face real-world challenges like:
- “How do I run 3 copies of this Pod?”
- “What if I want to update my app version without downtime?”
- “If a Pod crashes, who will restart it?”
- “How do I tell Kubernetes to keep watching and fix things?”
That’s where Deployments and ReplicaSets come in.
What Is a Deployment?
A Deployment is how you tell Kubernetes:
👉 “Here’s what I want. Please make it happen — and keep it that way.”
It’s a declarative object.
You don’t tell Kubernetes how to do it.
You just declare what you want — e.g.:
- Run 3 copies of this Pod
- Use this container image
- Expose it with this label
- Automatically update it when I say so
And Kubernetes will make that desired state true — and keep it that way.
What’s a ReplicaSet?
A ReplicaSet is a controller that maintains a specific number of Pods running at all times.
If you say: “Keep 3 Pods running,” the ReplicaSet will:
- Start 3 Pods if none exist
- Start 1 more if 1 crashes
- Delete 1 if you scale down to 2
🔁 A Deployment uses a ReplicaSet behind the scenes to make sure the correct number of Pods are always alive.
Real-World Analogy
Imagine a restaurant manager (Deployment) tells the team:
“We need 3 delivery bikes (Pods) on the road at all times.”
The supervisor (ReplicaSet) watches the bikes:
- If one breaks down, the supervisor sends out a new one
- If the manager says “increase to 5 bikes,” the supervisor dispatches 2 more
- If one returns early, the supervisor pulls it out of rotation
This teamwork ensures smooth service, always.
Rolling Updates Made Simple
Let’s say you’re launching version 2.0 of your app.
With Deployments, Kubernetes handles the update like this:
- Slowly replaces old Pods with new ones
- Keeps the app running during the update
- Rolls back if something goes wrong
This is called a rolling update — and it’s built-in!
Why Use Deployments Instead of Just Creating Pods?
Creating Pods Manually | Using Deployments |
---|---|
No auto-healing | Self-healing if Pods crash |
No scaling control | Easy scaling with one command |
No update mechanism | Rolling updates & rollbacks |
Not production-ready | Designed for real-world workloads |
Try It Yourself
Open the KodeKloud Kubernetes Playground:
👉 Launch Playground
Run this to create a Deployment:
kubectl create deployment myapp --image=nginx
kubectl get deployments
kubectl get pods
Then scale it:
kubectl scale deployment myapp --replicas=3
kubectl get pods
Boom — 3 Pods running, managed automatically!
Quick Summary
- Deployments tell Kubernetes your app's desired state
- ReplicaSets ensure that desired number of Pods are always running
- Together, they help with scaling, updates, and self-healing
- This is how Kubernetes keeps apps running reliably in production
🛎️ Coming Up...
📅 Day 5: Kubernetes Services — How Your App Gets a Stable IP or URL
You’ll learn:
- Why Pods alone aren’t enough to expose your app
- What a Service is
- How Kubernetes uses ClusterIP, NodePort, and LoadBalancer to make your app reachable
New here? Start from Day 1 and catch up on the series:
Day 1: What Is Kubernetes & Why Should You Care?
Discover why Kubernetes matters and how it changes the game.
Day 2: What Are Pods in Kubernetes?
Understand the smallest deployable unit in Kubernetes.
Day 3: Understanding Nodes, Clusters & the Kubernetes Control Plane
See how all the pieces connect behind the scenes.