How to fix unable to get metrics for resource cpu: no metrics returned from resource metrics API in Kubernetes
HPA (Horizontal Pod Autoscaler) cannot scale pods because metrics are unavailable, pods lack resource requests, or scaling constraints prevent replica changes. The HPA reports "FailedGetResourceMetric" error when Metrics Server is missing or metrics data is unavailable. Fix by installing Metrics Server, adding resource requests, or ensuring pods are ready.
Quick fix
Fixes unable to get metrics for resource cpu: no metrics returned from resource metrics API
kubectl get deployment metrics-server -n kube-system
kubectl get pods -n kube-system -l k8s-app=metrics-server
kubectl logs -n kube-system -l k8s-app=metrics-server- Verify Metrics Server is running
- Test metrics availability
- Add resource requests to all containers
- Verify pods are Ready
kubectl get deployment metrics-server -n kube-systemkubectl get pods -n kube-system -l k8s-app=metrics-serverkubectl logs -n kube-system -l k8s-app=metrics-serverunable to get metrics for resource cpu: no metrics returned from resource metrics API
What this error means
HPA requires Metrics Server to collect resource metrics (CPU, memory) from pods and nodes. Without metrics, HPA cannot calculate desired replica count. Even when Metrics Server is running, unready pods or missing resource requests cause metrics unavailable errors.
Typical symptoms
- HPA status shows `<unknown>` or `0/50` in TARGETS column
- kubectl describe hpa shows "FailedGetResourceMetric" event
- Pods stuck at minReplicas, no automatic scale-up during load
- Replicas unchanged despite high CPU/memory usage
- Events: "the HPA was unable to compute the replica count"
- ScalingActive condition shows False
Common causes
- Metrics Server not installed or not running
- Containers missing resource requests (HPA requires requests to calculate %)
- Unready pods ignored (metrics only counted from Ready pods)
- etcd or API server issues preventing metric retrieval
- Custom metrics API misconfigured or unavailable
- Nodes in NotReady state, unable to report metrics
How to fix "unable to get metrics for resource cpu: no metrics returned from resource metrics API"
Check if Metrics Server is deployed:
kubectl get deployment metrics-server -n kube-system
kubectl get pods -n kube-system -l k8s-app=metrics-server
kubectl logs -n kube-system -l k8s-app=metrics-serverIf not found, install:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yamlVerify metrics can be retrieved:
kubectl top nodes
kubectl top pods -n <namespace>If these fail with "metrics not found", Metrics Server issue. Check logs for TLS certificate or kubelet connectivity errors.
HPA requires resource requests to calculate utilization percentage:
resources:
requests:
cpu: 100m # REQUIRED for HPA
memory: 128Mi # REQUIRED for HPA
limits:
cpu: 500m
memory: 512MiApply to main app container AND all sidecars (Istio, etc.).
HPA ignores unready pods:
kubectl get pods -n <namespace> -o wide
kubectl describe pod <pod-name> -n <namespace> | grep -A5 "Conditions"All pods must be Running and Ready. Check readiness probe configuration.
Verify HPA targets valid metrics:
kubectl get hpa -n <namespace>
kubectl describe hpa <hpa-name> -n <namespace>Ensure:
- minReplicas < maxReplicas
- Metric names are valid (cpu, memory)
- Target utilization is reasonable (30-80%)
Watch HPA behavior:
kubectl get hpa <hpa-name> -n <namespace> --watch
# Generate load for testing
kubectl run -it --rm load -- busybox sh -c "while true; do wget -q -O- http://<service>; done"
# Monitor pod creation
kubectl get pods -n <namespace> --watchIf using custom metrics (not CPU/memory):
# Verify custom metrics adapter is running
kubectl get deployment -n custom-metrics
# Test custom metric availability
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jqEnsure adapter is installed and configured for your metrics provider.
Advanced notes
HPA with unready pods takes conservative approach: assumes 100% utilization, preventing scale-down. Add startupProbe with long failureThreshold (30-90) for slow-starting apps. For sidecars (Istio, Linkerd), use ContainerResource metric type (Kubernetes 1.27+) to scale based on main container only. Pod evictions count as replicas; monitor for involuntary disruptions.
Frequently asked questions
- What does "unable to get metrics for resource cpu: no metrics returned from resou" mean?
- HPA requires Metrics Server to collect resource metrics (CPU, memory) from pods and nodes. Without metrics, HPA cannot calculate desired replica count. Even when Metrics Server is running, unready pods or missing resource requests cause metrics unavailable errors.
- How do I fix "unable to get metrics for resource cpu: no metrics returned from resou"?
- HPA (Horizontal Pod Autoscaler) cannot scale pods because metrics are unavailable, pods lack resource requests, or scaling constraints prevent replica changes. The HPA reports "FailedGetResourceMetric" error when Metrics Server is missing or metrics data is unavailable. Fix by installing Metrics Server, adding resource requests, or ensuring pods are ready.
- What causes "unable to get metrics for resource cpu: no metrics returned from resou"?
- Metrics Server not installed or not running Containers missing resource requests (HPA requires requests to calculate %) Unready pods ignored (metrics only counted from Ready pods)
- Is the "unable to get metrics for resource cpu: no metrics returned from resou" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Kubernetes Official Documentation
- ๐Kubernetes Docs: horizontal pod autoscale(Official Docs)
- ๐
- ๐Kubernetes Docs: horizontal pod autoscale walkthrough(Official Docs)
- ๐