Command
kubectl scale deployment <deployment-name> --replicas=<n>Explanation
The 'kubectl scale deployment' command modifies the number of pod replicas defined for a deployment. This is a quick way to handle load adjustments or maintenance. The change is applied immediately, updating the deployment’s replica set to match the desired count. It does not modify autoscaling configurations.
Common Use Cases
- •Manually increase replicas during traffic spikes
- •Temporarily reduce replicas during maintenance or debugging
- •Test deployment behavior under different loads
Best Practices
- ✓Use autoscaling for production workloads instead of manual scaling
- ✓Verify scaling changes with 'kubectl get pods' after execution
Common Mistakes to Avoid
- ⚠Forgetting that manual scaling overrides HPA (Horizontal Pod Autoscaler) temporarily
- ⚠Using scale on a resource managed by an autoscaler without disabling it first
Troubleshooting
Problem: Deployment does not scale as expected
Solution: Ensure autoscaler is not overriding manual settings, and check for sufficient cluster resources.
Examples
Scale up to 5 replicas
kubectl scale deployment nginx-deploy --replicas=5Scale down to a single replica
kubectl scale deployment nginx-deploy --replicas=1