Skip to content
Latchkey

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=120s

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →