1001Ferramentas
📊Dev

Kubernetes HPA Generator

Generate a Kubernetes HorizontalPodAutoscaler (HPA) in YAML with min, max replicas and a CPU target. Scale your pods automatically as load changes.

YAML

Scaling pods automatically on CPU usage

The HorizontalPodAutoscaler is the Kubernetes object that raises and lowers the replica count of a Deployment as load changes. It watches a metric, compares it against the target you set and adjusts the count to bring the average back to that target. Without it, sizing means choosing between paying for idle capacity or having no headroom at peak.

Fill in the resource name, the target Deployment, the minimum and maximum replica bounds and the desired CPU percentage. The page returns the manifest on autoscaling/v2, the current version and the one that accepts multiple metrics. Save it to a file and apply with kubectl apply -f. A 70% target is a reasonable starting point: it leaves room for the time a new pod takes to come up and become ready.

One requirement sinks a lot of configurations: the CPU percentage is computed against each container's requests.cpu, not against the limit and not against node capacity. If the Deployment declares no CPU requests, the HPA cannot work out the ratio and sits there with no metric, showing unknown under kubectl get hpa. metrics-server also has to be installed in the cluster — without it, there is nowhere to read consumption from.

Frequently asked questions

Why does my HPA show unknown in the metric column?
The two usual causes are missing requests.cpu on the Deployment's containers and a missing metrics-server in the cluster. Check with kubectl top pods: if that command does not answer, the problem is metrics-server, not the HPA.
Can I scale on something other than CPU?
Yes. autoscaling/v2 accepts memory, custom metrics coming from Prometheus via an adapter, and external metrics such as queue depth. The manifest generated here carries only the CPU block, the most common case and the easiest to get right; the others go in as extra items in the metrics list.
Can an HPA coexist with a fixed replica count in the Deployment?
Badly. If the Deployment declares replicas while an HPA also manages the same object, every apply of the manifest reverts the count the autoscaler had set. Recommended practice is removing the replicas field from the Deployment once an HPA owns it.

Related Tools