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

← All kubectl commands · Docker vs Kubernetes