Skip to content
Latchkey

Kubernetes HPA "unable to fetch metrics" / "unknown" Targets in CI

A HorizontalPodAutoscaler needs a metrics source to compute utilization. When it shows <unknown> targets and unable to fetch metrics, the metrics-server (or custom-metrics adapter) is missing or unhealthy, or the pods declare no resource requests to measure against.

What this error means

kubectl get hpa shows TARGETS: <unknown>/80% and kubectl describe hpa reports FailedGetResourceMetric ... unable to fetch metrics from resource metrics API. The HPA never scales because it has no utilization signal.

kubectl describe hpa
Warning  FailedGetResourceMetric  horizontal-pod-autoscaler  failed to get cpu
utilization: unable to fetch metrics from resource metrics API: the server could
not find the requested resource (get pods.metrics.k8s.io)

Common causes

metrics-server not installed or unhealthy

The resource metrics API (metrics.k8s.io) is served by metrics-server. If it is not installed, crashing, or failing TLS to kubelets, the HPA has nothing to query.

Pods have no resource requests

CPU/memory utilization is computed as usage divided by the request. A targeted pod with no resources.requests gives the HPA no denominator, so the metric is <unknown>.

Custom/external metrics API missing

An HPA on a custom or external metric needs the corresponding adapter (e.g. prometheus-adapter). Without it, custom.metrics.k8s.io/external.metrics.k8s.io is not served.

How to fix it

Confirm the metrics API is served

Check that the metrics API responds and metrics-server is healthy before touching the HPA.

Terminal
kubectl get apiservices | grep metrics
kubectl top pods   # fails the same way if metrics-server is down
kubectl -n kube-system get deploy metrics-server

Install metrics-server and add requests

  1. Install/repair metrics-server so metrics.k8s.io is available.
  2. Set resources.requests.cpu/memory on the targeted pods so utilization can be computed.
  3. For custom metrics, install the adapter and confirm kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1 responds.

How to prevent it

  • Keep metrics-server (and any custom-metrics adapter) installed and monitored.
  • Always set resource requests on workloads that an HPA targets.
  • Validate kubectl top works as a pre-flight for HPA-driven deploys.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →