Scale a Deployment¶
When to Use This Guide¶
Use this guide when you need to increase or decrease the number of running pods for an application.
Scaling deployments is commonly required when:
- application traffic increases
- testing high availability
- reducing resource usage
- preparing for load testing
Quick Commands
kubectl scale deployment <deployment-name> --replicas=5
kubectl get deployment <deployment-name>
kubectl get pods
These commands allow you to quickly adjust the number of pods running in a deployment.
Common Scaling Tasks¶
| Task | Command |
|---|---|
| Increase replicas | kubectl scale deployment web-app --replicas=5 |
| Reduce replicas | kubectl scale deployment web-app --replicas=2 |
| Check replica status | kubectl get deployment web-app |
| View running pods | kubectl get pods |
Step 1 — Check Current Deployment Status¶
List deployments in the namespace.
Example:
This indicates the deployment currently runs 2 pods.
Step 2 — Scale the Deployment¶
Increase the number of replicas.
Output:
Kubernetes immediately begins creating additional pods.
Step 3 — Verify the New Pods¶
Check that new pods are starting.
Example:
web-app-7f8d9c6d4b-abc12
web-app-7f8d9c6d4b-def34
web-app-7f8d9c6d4b-ghi56
web-app-7f8d9c6d4b-jkl78
web-app-7f8d9c6d4b-mno90
Step 4 — Confirm Deployment Status¶
Verify that the deployment has reached the desired state.
Example:
Automatic Scaling with HPA¶
For dynamic workloads, Kubernetes can automatically scale deployments using the Horizontal Pod Autoscaler (HPA).
Create an autoscaler:
This tells Kubernetes to:
- maintain CPU usage around 70%
- run 2–10 pods depending on load
Verify Autoscaling¶
Check autoscaler status:
Example:
Common Issues¶
New Pods Remain Pending
Possible causes:
- insufficient cluster resources
- node scheduling constraints
- missing persistent volumes
Investigate using:
Pods Crash After Scaling
This usually indicates an application issue rather than a scaling problem.
Check logs:
Quick Scaling Workflow
Most scaling tasks follow this pattern:
Related Guides¶
Deployment Management
- Roll Back a Deployment
- Restart a Deployment
Troubleshooting
- Debug a Crashing Pod
- View Container Logs