How to fix unable to compute replica count in Kubernetes

KubernetesINTERMEDIATEMEDIUMUpdated Dec 5, 2025· 219 views

The Horizontal Pod Autoscaler cannot calculate the desired number of replicas because it's missing critical input data—either metrics are unavailable or resource requests are not defined on containers.

Quick fix

Fixes unable to compute replica count

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 | head -50
  1. Verify Metrics Server is installed and healthy
  2. Verify metrics are being collected
  3. Add missing resource requests to all containers
  4. Add resource requests to injected sidecar containers
kubernetes — error
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 | head -50
unable to compute replica count

What this error means

The Kubernetes Horizontal Pod Autoscaler (HPA) uses a specific calculation formula to determine the desired number of replicas: desiredReplicas = ceil[currentReplicas × (currentMetricValue / desiredMetricValue)]. When the HPA reports 'unable to compute replica count', it means the controller cannot complete this calculation because it's missing critical input data. This error typically occurs at the metrics gathering stage. The HPA requires real-time metrics from the Kubernetes Metrics Server to calculate utilization ratios. For CPU/memory scaling, it needs both the current usage (from metrics) and the requested resources (from pod specs) to compute utilization as a percentage. Without either piece, the division fails and scaling decisions cannot be made. The error may also occur when there are zero running replicas or when custom metrics endpoints are misconfigured.

Typical symptoms

  • HPA describe output shows "FailedComputeMetricsReplicas" or "FailedGetResourceMetric" warning events
  • Pods do not scale up despite high CPU/memory usage consistently exceeding the target threshold
  • kubectl top pods returns "unknown" for resource metrics or shows no output
  • HPA CurrentReplicas matches DesiredReplicas but stays at minimum, even under load
  • Events log shows "the HPA was unable to compute the replica count: missing request for cpu/memory"
  • Deployment or StatefulSet remains stuck at minReplicas without auto-scaling during traffic spikes

Common causes

  1. Missing resource requests (cpu/memory) on one or more containers in the target pods
  2. Metrics Server is not installed, not running, or not responding
  3. Sidecar containers injected by service meshes lacking their own resource requests
  4. Custom metrics API endpoint misconfigured or Prometheus Adapter not deployed
  5. Zero running replicas or all pods in NotReady state—no pods exist to provide metrics
  6. Metrics Server or API server version mismatch causing metrics API to reject queries
  7. Network connectivity issue between HPA controller and Metrics Server

How to fix "unable to compute replica count"

1Verify Metrics Server is installed and healthy

Check if the Metrics Server deployment exists and is running:

bash
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 | head -50

If metrics-server is missing, install it:

bash
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
2Verify metrics are being collected

Test that the Metrics Server can gather and serve metrics:

bash
kubectl top nodes
kubectl top pods -n <namespace>

If these commands return 'unknown' or 'Metrics not available yet', metrics collection is not working. Check Metrics Server logs for errors like 'TLS errors', 'connection refused', or 'unauthorized'.

3Add missing resource requests to all containers

The HPA cannot calculate utilization without knowing how much CPU/memory each pod requested. Update your Deployment with explicit requests:

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  template:
    spec:
      containers:
      - name: app
        image: myimage:1.0
        resources:
          requests:
            cpu: 250m
            memory: 256Mi
          limits:
            cpu: 500m
            memory: 512Mi

Apply and rollout:

bash
kubectl apply -f deployment.yaml
kubectl rollout status deployment/myapp -n <namespace>
4Add resource requests to injected sidecar containers

If you use Istio, Linkerd, or other service meshes, proxies are automatically injected but often lack resource requests.

For Linkerd, add this annotation to your pod spec:

yaml
spec:
  template:
    metadata:
      annotations:
        config.linkerd.io/proxy-cpu-request: 100m
        config.linkerd.io/proxy-memory-request: 64Mi

For Istio, configure the sidecar injector to include resource requests:

bash
kubectl get configmap istio-sidecar-injector -n istio-system -o yaml | grep -A 20 "resources:"

Recreate pods after updating to apply sidecar changes.

5Check HPA configuration and describe events

Examine the HPA object to understand what's failing:

bash
kubectl get hpa -n <namespace>
kubectl describe hpa <hpa-name> -n <namespace>

Look for:
- Metrics: Verify it matches your container's resource requests
- Conditions: Look for 'ScalingActive = False' which indicates metrics cannot be fetched
- Events: Recent events will show exact errors like 'missing request for cpu'

6Verify at least one pod is running and Ready

The HPA cannot compute metrics if there are zero replicas running:

bash
kubectl get pods -n <namespace> -l app=myapp
kubectl describe pod <pod-name> -n <namespace>

If minReplicas is 0 or pods are terminated, scale the deployment to at least 1:

bash
kubectl scale deployment myapp --replicas=1 -n <namespace>

Wait for the pod to reach Ready state, then verify metrics appear:

bash
kubectl top pods -n <namespace>

Note: Standard HPA cannot scale down to zero. For scale-to-zero, consider KEDA.

Advanced notes

HPA calculates desired replicas as: desiredReplicas = ceil[currentReplicas × (currentMetricValue / targetMetricValue)]. The controller applies a default tolerance of 10% before scaling, meaning it ignores recommendations when the ratio is between 0.9 and 1.1 to prevent thrashing.

When an HPA specifies multiple metrics (e.g., CPU and memory), the controller calculates desired replicas for each metric independently, then selects the largest value. If any metric cannot be fetched, the HPA skips scale-down decisions but can still scale up if other metrics indicate demand.

If the deployment is scaled to 0 replicas, no pods exist to provide metrics, creating a catch-22. The standard HPA cannot scale from zero (requires at least minReplicas = 1). For workloads that should completely shut down during idle, use KEDA with event-driven scaling.

Resource Request Validation: HPA will not scale if resource.requests is missing or zero. Using only resource.limits (without requests) is insufficient. Setting identical requests and limits is valid but defeats HPA's purpose by preventing flexible scaling.

After fixing metrics issues, allow 30-60 seconds for metrics to propagate, then another sync period (default 15 seconds) for HPA controller to re-evaluate.

Frequently asked questions

What does "unable to compute replica count" mean?
The Kubernetes Horizontal Pod Autoscaler (HPA) uses a specific calculation formula to determine the desired number of replicas: desiredReplicas = ceil[currentReplicas × (currentMetricValue / desiredMetricValue)]. When the HPA reports 'unable to compute replica count', it means the controller cannot complete this calculation because it's missing critical input data. This error typically occurs at the metrics gathering stage.
How do I fix "unable to compute replica count"?
The Horizontal Pod Autoscaler cannot calculate the desired number of replicas because it's missing critical input data—either metrics are unavailable or resource requests are not defined on containers.
What causes "unable to compute replica count"?
Missing resource requests (cpu/memory) on one or more containers in the target pods Metrics Server is not installed, not running, or not responding Sidecar containers injected by service meshes lacking their own resource requests
Is the "unable to compute replica count" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading