lifecycle
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 autoscale (-f FILENAME | TYPE NAME) --min=MIN --max=MAX [--cpu-percent=CPU] [flags] Common flags
| Flag | Purpose |
|---|---|
| --min | Minimum replica count. |
| --max | Maximum replica count (required). |
| --cpu-percent | Target average CPU utilization percentage. |
| --name | Name for the HPA object (defaults to the target's name). |
| -n, --namespace | Namespace for the HPA. |
Examples
kubectl autoscale deploy/web --min=2 --max=10 --cpu-percent=70 Create an HPA targeting 70% average CPU.
kubectl autoscale rs/api --max=5 Autoscale a ReplicaSet with default CPU target.
kubectl autoscale statefulset/worker --min=3 --max=12 --cpu-percent=60 HPA on a StatefulSet.
Gotcha
Requires metrics-server (or an equivalent) for CPU metrics; without it the HPA reports unknown targets. For memory or custom metrics, write the HPA v2 manifest by hand.
Related commands
kubectl scale
Sets a new desired replica count for a Deployment, StatefulSet, ReplicaSet, or ReplicationController. Optional preconditions guard against racing with another controller.
kubectl top
Displays CPU and memory usage for nodes or pods, powered by the metrics.k8s.io API. Requires the metrics-server (or an equivalent aggregator) to be installed in the cluster.
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 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.