kubernetes autoscaling_error ai_generated true

failed to get cpu utilization: unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API

ID: kubernetes/k8s-hpa-unable-to-fetch

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
55Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8 active

Root Cause

HPA cannot fetch metrics because metrics-server is not installed, not healthy, or pods lack resource requests.

generic

Workarounds

  1. 92% success Install or fix metrics-server: kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
    Check if metrics-server is running: kubectl get pods -n kube-system | grep metrics-server

    Sources: https://kubernetes.io/docs/tasks/debug/debug-cluster/resource-metrics-pipeline/

  2. 90% success Ensure all target pods have resource requests defined
    Add resources.requests.cpu and resources.requests.memory to pod spec containers

    Sources: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/

Dead Ends

Common approaches that don't work:

  1. Manually scale replicas instead of using HPA 70% fail

    Loses autoscaling capability — doesn't address the root cause

  2. Switch to custom metrics without fixing resource metrics first 65% fail

    Custom metrics require additional setup (Prometheus adapter) and are more complex

Error Chain

Leads to:
Preceded by:
Frequently confused with: