kubectl 1.37 reference · Workloads
kubectl scale Command (kubectl)
Set the number of replicas of a Deployment, ReplicaSet or StatefulSet; avoid it for workloads managed by an autoscaler.
kubectl 1.37
Syntax
kubectl scale RESOURCE/NAME --replicas=N [--current-replicas=N]
Parameters
| Parameter | Description |
|---|---|
--replicas=N |
Desired replica count. |
--current-replicas=N |
Only scale if the current count matches (a safety check). |
Examples
kubectl create namespace rc-ref-scale > /dev/null
trap 'kubectl delete namespace rc-ref-scale --wait=false > /dev/null' EXIT
kubectl -n rc-ref-scale create deployment api --image=busybox:1.37 -- sleep 3600 > /dev/null
kubectl -n rc-ref-scale scale deployment/api --replicas=3
kubectl -n rc-ref-scale rollout status deployment/api --timeout=120s > /dev/null
kubectl -n rc-ref-scale get deployment api -o jsonpath='ready: {.status.readyReplicas}{"\n"}'
Output
deployment.apps/api scaled ready: 3
Run this on your computer — see “Get Started” for setup.
kubectl create namespace rc-ref-scale2 > /dev/null
trap 'kubectl delete namespace rc-ref-scale2 --wait=false > /dev/null' EXIT
kubectl -n rc-ref-scale2 create deployment api --image=busybox:1.37 -- sleep 3600 > /dev/null
kubectl -n rc-ref-scale2 scale deployment/api --current-replicas=5 --replicas=2 2>&1 | sed 's/^error: //' | cut -c1-70
Output
Expected replicas to be 5, was 1
Run this on your computer — see “Get Started” for setup.
Related
kubectl rollout· Manage Deployment, StatefulSet and DaemonSet rollouts: watch status, view history, restart and undo to a previous revision.- Scaling · tutorial