A Deployment in Kubernetes is a higher-level controller that manages ReplicaSets and provides declarative updates for Pods and applications.
In simpler terms →
👉 Deployment = Automated management + scaling + rolling updates for your Pods.
⚙️ Definition
A Deployment defines the desired state of your application (like number of replicas, container image, etc.), and Kubernetes automatically manages that state — creating or updating Pods as needed.
🧩 Core Features
- Declarative Updates — You describe what you want (e.g., 5 replicas, new image), and Kubernetes makes it so.
- Rolling Updates — Deploy new versions of your app gradually without downtime.
- Rollback — Easily revert to a previous stable version if something goes wrong.
- Self-Healing — Automatically replaces crashed or unresponsive Pods.
- Scaling — Adjust replicas manually or via autoscaling.
🧾 Example YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: nginx-container
image: nginx:1.25
ports:
- containerPort: 80
Explanation:
replicas: 3
→ ensures 3 Pods are running.selector.matchLabels
→ connects the Deployment to its Pods.template
→ defines the Pod specification (containers, images, ports, etc.).
🔄 How It Works Internally
- You create or update a Deployment.
- The Deployment creates a ReplicaSet to manage the Pods.
- During an update:
- A new ReplicaSet is created with the new configuration.
- Pods from the old ReplicaSet are gradually replaced with Pods from the new one.
- Kubernetes ensures zero downtime through this rolling update process.
- You can rollback to a previous ReplicaSet if needed.
📊 Typical Workflow
- Deploy your application with a Deployment.
- Scale it (e.g.,
kubectl scale deployment myapp-deployment --replicas=5
). - Update the image version (e.g.,
kubectl set image deployment myapp-deployment nginx-container=nginx:1.26
). - Monitor rollout status (
kubectl rollout status deployment myapp-deployment
). - Rollback if necessary (
kubectl rollout undo deployment myapp-deployment
).
🧠 Key Differences
Concept | Description | Manages |
---|---|---|
Pod | Smallest deployable unit (one or more containers) | Containers |
ReplicaSet | Ensures the desired number of Pods | Pods |
Deployment | Manages ReplicaSets and enables rolling updates | ReplicaSets |
🚀 Common Use Cases
- Deploying stateless applications (e.g., web servers, APIs).
- Performing zero-downtime application upgrades.
- Scaling workloads up/down based on demand.
- Managing multiple versions of an application safely.