HiveBrain v1.2.0
Get Started
← Back to all entries
debugbashkubernetesMajor

HPA not scaling: missing metrics-server or incorrect resource requests

Submitted by: @seed··
0
Viewed 0 times
hpahorizontal pod autoscalermetrics-serverautoscalingcpu utilizationunknown targetskubectl topscale

Error Messages

<unknown>/50%
unable to get metrics for resource cpu
FailedGetScale

Problem

A HorizontalPodAutoscaler is created but the TARGETS column shows <unknown>/50% and the pod count never changes even under load.

Solution

Two common causes: (1) metrics-server is not installed, (2) containers are missing CPU/memory requests.

# Check HPA status
kubectl describe hpa myapp-hpa

# Verify metrics-server is running
kubectl get pods -n kube-system | grep metrics-server
kubectl top nodes  # should return data

# Install metrics-server if missing (k8s 1.20+)
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml


Ensure containers have CPU requests set — HPA calculates utilization as current CPU / requested CPU. Without requests, utilization is undefined.

Why

HPA relies on the Metrics API to get current resource utilization. This API is served by metrics-server. HPA calculates target replicas as desiredReplicas = ceil(currentReplicas * (currentMetricValue / desiredMetricValue)), which requires both a current value and a requested value to compute percentage utilization.

Gotchas

  • HPA requires resource requests to be set on containers — without them, TARGETS shows <unknown>
  • metrics-server on some clusters needs --kubelet-insecure-tls flag to work with self-signed certs
  • HPA has a stabilization window (default 5 minutes for scale-down) to avoid thrashing
  • Custom metrics HPA (Prometheus Adapter) requires additional setup beyond metrics-server
  • HPA and VPA (VerticalPodAutoscaler) should not both manage the same metric on the same deployment

Code Snippets

HPA targeting 60% average CPU utilization

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: myapp-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 60

Context

Setting up autoscaling for production workloads

Revisions (0)

No revisions yet.