kubectl scale: Command Reference for CI/CD
Set the replica count up or down in a single command.
kubectl scale changes a workload desired replica count. CI uses it to park preview environments at zero or scale a worker pool for a load test. This reference covers the flags, conditional scaling, and the HPA conflict.
Common flags and usage
- scale deploy/<name> --replicas=N: set the replica count
- --current-replicas=M: only scale if currently at M (avoids races)
- --replicas=0: park a preview environment
- -f <manifest>: scale the workload defined in a file
- Returns when the spec is updated, not when pods are Ready
Example
shell
# Park the preview env at the end of a PR pipeline
kubectl scale deploy/web --replicas=0
# Scale up for a load test, then gate on readiness
kubectl scale deploy/web --current-replicas=2 --replicas=10
kubectl rollout status deploy/web --timeout=120sIn CI
If a HorizontalPodAutoscaler manages the Deployment, it scales your manual change straight back, so the count silently reverts: adjust the HPA bounds instead. scale does not wait for readiness, so follow it with rollout status when the pipeline depends on the new pods.
Key takeaways
- An HPA overrides a manual scale; change the HPA bounds instead.
- --current-replicas makes scaling conditional and race-safe.
- scale returns on spec update, not readiness; gate with rollout status.
Related guides
kubectl Cheat Sheet: Commands for Everyday KubernetesA kubectl cheat sheet - get, describe, logs, apply, rollout, debug, and context commands for daily Kubernetes…
kubectl rollout status: Command Reference for CI/CDReference for kubectl rollout status: block until a rollout completes and exit non-zero on failure, the canon…
kubectl get: Command Reference for CI/CDReference for kubectl get: list resources, output formats, label and field selectors, jsonpath extraction, an…
kubectl patch: Command Reference for CI/CDReference for kubectl patch: apply strategic-merge, JSON-merge, or JSON-patch updates from a script, when to…