The HPA (Horizontal Pod Autoscaler) error about unable to get CPU metrics indicates the Metrics Server is not installed, misconfigured, or pods lack resource requests. Without metrics, HPA cannot determine if pods need more replicas.
HPA relies on the Metrics Server to collect CPU and memory metrics from the kubelet on each node. These metrics are then used to determine if pods need scaling. The "unable to get metrics" error means either: 1. Metrics Server is not installed in the cluster 2. Pods lack CPU resource requests (HPA uses requests to calculate percentages) 3. Metrics API is unreachable or misconfigured 4. Pods are not in Ready state (metrics only available for running pods) Without metrics, HPA cannot make scaling decisions and remains in "Waiting for metrics" state indefinitely.
Verify Metrics Server is running:
kubectl get deployment -n kube-system metrics-server
kubectl get pods -n kube-system | grep metrics-serverIf not found, install it:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yamlWait 30-60 seconds for the pod to start, then verify:
kubectl get pods -n kube-system metrics-server -o wide
kubectl logs -n kube-system deployment/metrics-serverHPA requires resource requests to calculate CPU utilization. Update your deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
template:
spec:
containers:
- name: app
image: myapp:latest
resources:
requests:
cpu: 100m # Required for HPA
memory: 128Mi # Optional but recommended
limits:
cpu: 500m
memory: 512MiApply:
kubectl apply -f deployment.yamlMetrics should be available 15-60 seconds after pod startup.
HPA only metrics for Ready pods. Check status:
kubectl get pods
kubectl describe pod <pod-name>If pods are not Ready, fix the underlying issues first (image pull errors, health check failures, resource constraints). Once pods are Running and Ready:
kubectl top pods # Should show CPU/memory nowVerify the Metrics API is working:
kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes
kubectl get --raw /apis/metrics.k8s.io/v1beta1/namespaces/default/podsIf this returns valid JSON with metrics, the API is working. If it returns errors, check Metrics Server logs:
kubectl logs -n kube-system deployment/metrics-serverCommon errors:
- "Unauthorized" or "Forbidden": RBAC permissions issue
- "Connection refused": Metrics Server not running or API unavailable
Get detailed error information:
kubectl logs -n kube-system deployment/metrics-server -f
kubectl describe pod -n kube-system -l k8s-app=metrics-serverCommon issues:
- "Unable to connect to Kubelet": Firewall blocking port 10250, or Kubelet not running
- "Forbidden": RBAC permissions missing for Metrics Server
- "CrashLoopBackOff": Pod startup failure (check earlier logs)
If Metrics Server is crashing, check available resources and restart it:
kubectl rollout restart deployment -n kube-system metrics-serverFrom the control plane, test kubelet metrics port:
kubectl get nodes -o wide # Get node IPs
curl -k --cert /var/run/kubernetes/client-admin.crt \
--key /var/run/kubernetes/client-admin.key \
https://<node-ip>:10250/metricsIf this fails with connection refused, kubelet isn't exposing metrics. Verify kubelet is running on the node:
ssh <node-ip>
sudo systemctl status kubelet
netstat -tlnp | grep 10250Once metrics are available, test with a simple HPA:
# Create a test deployment with metrics
kubectl create deployment hpa-test --image=nginx --replicas=1 -- sleep 3600
kubectl set resources deployment hpa-test --requests=cpu=100m
# Create HPA
kubectl autoscale deployment hpa-test --min=1 --max=3 --cpu-percent=50
# Check HPA status
kubectl get hpa -w
kubectl describe hpa hpa-testOnce metrics become available (15-60 seconds), HPA should show CPU percentage instead of "unknown".
Metrics are not immediately available after pod creation:
# Right after pod start:
kubectl top pod <pod-name> # May return "no metrics"
# Wait 15-60 seconds:
watch kubectl top pod <pod-name>Metrics become available once the kubelet has collected data from the container runtime. Be patient—metrics typically appear within 1-2 minutes for healthy pods.
If Metrics Server cannot access Kubelet metrics, RBAC may be too strict. Verify:
kubectl get clusterrole system:metrics-server -o yaml
kubectl get clusterrolebinding system:metrics-server -o yamlMetrics Server needs permissions to:
- Get nodes and node metrics
- Access kubelet stats endpoints
- List pods in all namespaces
If using restrictive RBAC, ensure the Metrics Server ClusterRole includes these permissions.
Metrics Server is essential for HPA to function—it's not optional. In Minikube, use minikube addons enable metrics-server. In Docker Desktop, Metrics Server must be installed manually. Cloud providers (EKS, AKS, GKE) often don't include Metrics Server by default—check provider docs. Resource requests are mandatory for HPA; without them, HPA cannot calculate CPU percentage (e.g., 50% of what?). Metrics have a 1-2 minute lag, so HPA scaling decisions are delayed. For real-time scaling needs, consider custom metrics via Prometheus. In resource-constrained clusters, Metrics Server itself may be the bottleneck—ensure it has sufficient CPU/memory. High-frequency metric collection (low --metric-resolution) increases kubelet load; adjust if needed.
No subnets found for EKS cluster
How to fix "eks subnet not found" in Kubernetes
unable to compute replica count
How to fix "unable to compute replica count" in Kubernetes HPA
error: context not found
How to fix "error: context not found" in Kubernetes
default backend - 404
How to fix "default backend - 404" in Kubernetes Ingress
serviceaccount cannot list resource
How to fix "serviceaccount cannot list resource" in Kubernetes