lifecycle
kubectl scale
Sets a new desired replica count for a Deployment, StatefulSet, ReplicaSet, or ReplicationController. Optional preconditions guard against racing with another controller.
kubectl scale [--resource-version=VERSION] [--current-replicas=COUNT] --replicas=COUNT TYPE/NAME Common flags
| Flag | Purpose |
|---|---|
| --replicas | Target replica count (required). |
| --current-replicas | Precondition: only scale if the current count matches. |
| --resource-version | Precondition: only scale if the resourceVersion matches. |
| -f, --filename | Scale the resource(s) referenced in a file. |
| --timeout | How long to wait for the scale action to be accepted. |
Examples
kubectl scale deploy/web --replicas=5 Scale to 5 replicas.
kubectl scale statefulset/db --replicas=0 Drain a StatefulSet to zero for maintenance.
kubectl scale --current-replicas=3 --replicas=6 deploy/web Scale only if current count is 3 (safety guard).
Gotcha
scale is one-shot and imperative - an HPA can immediately reset your value. For persistent changes, edit the manifest instead.
Related commands
kubectl autoscale
Creates a HorizontalPodAutoscaler (v2) that scales a workload based on CPU utilization. For memory or custom/external metrics, author the HPA manifest directly since this command only exposes CPU targets.
kubectl rollout
Manages the deployment lifecycle of Deployments, StatefulSets, and DaemonSets. Subcommands cover watching progress, rolling back to a revision, restarting all pods, and pausing/resuming controller reconciliation.
kubectl apply
Declaratively creates or updates resources from a manifest file, directory, URL, or kustomization. Tracks the last-applied configuration so subsequent applies compute a three-way merge patch rather than replacing the object.
kubectl delete
Deletes one or more resources by name, label, or manifest. Supports graceful termination, forced eviction of stuck pods, and cascading deletion of owned objects.
kubectl run
Imperatively creates a single Pod running a specified image. In modern kubectl it only produces a Pod (Deployment/Job generators were removed) - use it for ad-hoc debugging containers, not durable workloads.