# kubectl scale: Command Reference for CI/CD

> Reference for kubectl scale: set replica counts, conditional scaling with --current-replicas, why an HPA fights a manual scale, and a CI example.

Source: https://latchkey.dev/learn/command-reference/kubectl-scale-command-cli-reference  
Updated: 2026-06-26

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.

## Using this in CI

A runner has no kubeconfig, no cached context, and no interactive auth. Every kubectl invocation in CI needs the context supplied explicitly, and most confusing CI failures here are the command running against the wrong cluster or no cluster at all.

```Terminal
# never rely on the ambient context on a runner
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get pods

# confirm what you are actually connected to before mutating anything
kubectl config current-context
kubectl cluster-info

# fail fast instead of hanging on an unreachable API server
kubectl --request-timeout=30s get nodes
```

> Always set `--request-timeout` in CI. Without it an unreachable API server hangs until the job times out, which turns a thirty-second failure into a twenty-minute one.

## FAQ

### kubectl scale: Command Reference for CI/CD?

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.

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
