Skip to content
Latchkey

kubectl scale: Usage, Options & Common CI Errors

Set the replica count up or down in one command.

kubectl scale changes the desired replica count of a scalable controller. It is common in CI for scaling down a preview environment or scaling a job-runner deployment for a load test.

What it does

kubectl scale --replicas=N sets the replica field on a Deployment, ReplicaSet, StatefulSet, or ReplicationController. --current-replicas makes the change conditional (only scale if currently at M), which avoids racing another actor. It returns once the spec is updated, not once pods are Ready.

Common usage

Terminal
kubectl scale deploy/web --replicas=5
kubectl scale statefulset/db --replicas=3
kubectl scale deploy/web --replicas=0          # park a preview env
kubectl scale deploy/web --current-replicas=2 --replicas=4
kubectl scale --replicas=3 -f deploy.yaml

Common errors in CI

The most confusing "failure" is no error at all: you scale a Deployment that is also managed by a HorizontalPodAutoscaler, and the HPA immediately scales it back, so your replica count silently reverts. Scale the HPA bounds (or delete it) instead of the Deployment. "the object has been modified; please apply your changes to the latest version" on --current-replicas means another controller changed the count between read and write - re-read and retry. Remember scale does not wait for readiness; follow it with kubectl rollout status if the pipeline depends on the new pods being up.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →