Home / OCI

OCITroubleshootingIntermediate

OKE Horizontal Pod Autoscaler not scaling: metrics server add-on, kubectl top errors and missing resource requests

HPA shows <unknown> targets or never adds replicas on OKE. Check the Metrics Server add-on and cert-manager, the metrics APIService, pod resource requests and the HPA conditions.

Deepak Bhardwaj7 min read

Applies toOracle Kubernetes Engine (OKE) basic and enhanced clusters, KubernetesMetricsServer and CertManager cluster add-ons, autoscaling/v2 HorizontalPodAutoscaler

Symptom

You see one or more of these on an OKE cluster:

  • kubectl get hpa shows TARGETS as <unknown>/70% and the replica count never changes.
  • kubectl top nodes or kubectl top pods fails with error: Metrics API not available.
  • kubectl describe hpa shows FailedGetResourceMetric or FailedComputeMetricsReplicas.
  • The HPA reads metrics fine but stays at minReplicas while the pods are clearly busy.

The Horizontal Pod Autoscaler gets CPU and memory figures from the resource metrics API (metrics.k8s.io). OKE does not serve that API until you deploy a metrics server. If the API is missing or unreachable, the HPA cannot compute anything and holds its current replica count.

Quick checks

Run these four commands first. Together they show which layer is broken.

# 1. Is the resource metrics API registered and Available?
kubectl get apiservice v1beta1.metrics.k8s.io

# 2. Is metrics-server running?
kubectl get deployment metrics-server -n kube-system
kubectl get pods -n kube-system | grep metrics-server

# 3. Does the API return data?
kubectl top nodes

# 4. What does the HPA itself say?
kubectl describe hpa <hpa-name> -n <namespace>
What you see Likely cause Go to
apiservice ... not found No metrics server deployed Install the add-on
APIService False (MissingEndpoints) metrics-server pods not running or not Ready metrics-server pods failing
APIService False (FailedDiscoveryCheck) API server can't reach the metrics-server pod Network path
kubectl top works, HPA says missing request for cpu Pods have no CPU request Resource requests
HPA has metrics but doesn't scale Target, limits or behavior settings HPA logic

Install the Metrics Server add-on

OKE offers the Kubernetes Metrics Server as a cluster add-on named KubernetesMetricsServer. Oracle manages its version and updates. The add-on needs cert-manager in the cluster. You can install cert-manager as the CertManager add-on, or run your own open-source cert-manager and set the skipAddonDependenciesCheck configuration argument to true.

Check what is already installed:

CLUSTER_ID=ocid1.cluster.oc1..example
oci ce cluster list-addons --cluster-id "$CLUSTER_ID" \
  --query 'data[].{name:name,state:"lifecycle-state",version:"current-installed-version"}' \
  --output table

To see which add-on versions your Kubernetes version supports:

oci ce addon-option list --kubernetes-version v1.31.1 \
  --addon-name KubernetesMetricsServer

Version strings vary. Copy the exact value from oci ce cluster get --cluster-id "$CLUSTER_ID" --query 'data."kubernetes-version"'.

Install cert-manager first if it isn't there, then the metrics server. A minimal configuration file is enough:

cat > certmanager.json <<'EOF'
{ "addonName": "CertManager", "configurations": [] }
EOF

cat > metrics-server.json <<'EOF'
{ "addonName": "KubernetesMetricsServer", "configurations": [] }
EOF

oci ce cluster install-addon --cluster-id "$CLUSTER_ID" \
  --addon-name CertManager --from-json file://./certmanager.json

# Wait until CertManager shows ACTIVE in list-addons, then:
oci ce cluster install-addon --cluster-id "$CLUSTER_ID" \
  --addon-name KubernetesMetricsServer --from-json file://./metrics-server.json

Each install returns a work request. If the add-on ends up NEEDS_ATTENTION or FAILED, read the work request errors:

oci ce work-request list --compartment-id <compartment-ocid> --cluster-id "$CLUSTER_ID" \
  --query 'data[0:5].{id:id,op:"operation-type",status:status}' --output table
oci ce work-request-error list --compartment-id <compartment-ocid> --work-request-id <wr-ocid>

Warning

Don't run the add-on and a self-installed metrics-server (Helm chart or upstream components.yaml) side by side. Both register v1beta1.metrics.k8s.io and the one applied last wins. Remove the self-managed copy before you enable the add-on.

If you need to back it out, oci ce cluster disable-addon --addon-name KubernetesMetricsServer --cluster-id "$CLUSTER_ID" --is-remove-existing-add-on true removes it. With false, it stays deployed but Oracle stops updating it.

metrics-server pods failing

If the APIService says MissingEndpoints, look at the pods:

kubectl -n kube-system describe pod -l k8s-app=metrics-server
kubectl -n kube-system logs deploy/metrics-server --tail=50

Common log lines:

Log message Meaning Fix
x509: certificate signed by unknown authority / cannot validate certificate when scraping nodes metrics-server can't verify kubelet serving certs Usually a self-managed install with the wrong flags. Use the add-on, or fix the --kubelet-* flags
dial tcp <node-ip>:10250: i/o timeout Node-to-node or pod-to-node traffic to kubelet port 10250 is blocked Allow TCP 10250 from the pod CIDR or pod subnet to the worker subnet
no metrics known for node Scrape hasn't finished yet or failed for that node Wait one scrape interval, then check that node's kubelet
Pod Pending No schedulable node (taints, all nodes full) Check kubectl describe pod events

The label selector k8s-app=metrics-server is the upstream default. Add-on versions can differ, so if it matches nothing, use kubectl -n kube-system get pods --show-labels | grep metrics.

Network path: FailedDiscoveryCheck

The Kubernetes API server calls the metrics-server pod directly through the aggregation layer. On OKE the control plane runs in the Kubernetes API endpoint subnet, so traffic has to get from that subnet to the metrics-server pod on its container port.

  • Flannel overlay clusters: the worker subnet's security list or NSG must allow ingress from the API endpoint subnet CIDR to the workers. The default OKE network rules include this. Custom hardened rules often drop it.
  • VCN-native pod networking: pods have their own subnet. Allow ingress from the API endpoint subnet to the pod subnet on the metrics-server port, and allow egress from the pod subnet to the workers on TCP 10250 for kubelet scraping.

Find the actual container port, because it differs between versions:

kubectl -n kube-system get deploy metrics-server \
  -o jsonpath='{.spec.template.spec.containers[0].ports}{"\n"}'
kubectl get apiservice v1beta1.metrics.k8s.io -o jsonpath='{.status.conditions}{"\n"}'

If the condition message mentions a timeout, use VCN flow logs or Network Path Analyzer between the API endpoint subnet and the pod IP to find the rule that drops it.

Resource requests: missing request for cpu

kubectl top can work while the HPA still shows <unknown>. A utilization target is a percentage of the container's request. If any container in the pod, sidecars included, has no CPU request, the HPA can't compute utilization for the pod.

kubectl get deploy <name> -n <namespace> \
  -o jsonpath='{range .spec.template.spec.containers[*]}{.name}{"\t"}{.resources.requests}{"\n"}{end}'

Set requests on every container, or switch the HPA to an AverageValue target, which needs no request:

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: web
  namespace: shop
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web
  minReplicas: 3
  maxReplicas: 20
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300

Tip

A LimitRange in the namespace can add default requests to pods that don't declare them. That fixes the HPA for teams that forget, but it also changes scheduling. Check your node capacity first.

HPA has metrics but doesn't scale

Read the conditions in kubectl describe hpa:

  • ScalingLimited ... TooManyReplicas: you've reached maxReplicas. Raise it, and check that the node pool or Cluster Autoscaler can supply the nodes.
  • AbleToScale ... BackoffBoth or ScaleDownStabilized: the stabilization window is holding the count. That's expected for scale-down (default 300 seconds).
  • Utilization is high but under target: the request is set too high compared with real usage, so 70% of the request is never reached. Lower the request or the target.
  • New replicas stay Pending: the HPA did its job. Now you have a capacity problem. See the Cluster Autoscaler checks.

Watch it live while you generate load:

kubectl get hpa web -n shop -w
kubectl top pods -n shop --containers

Prevent it next time

  • Enable CertManager and KubernetesMetricsServer add-ons in the cluster Terraform or creation script, so every new cluster has the metrics API on day one.
  • Add a post-deployment smoke test: kubectl get apiservice v1beta1.metrics.k8s.io must report True.
  • Enforce CPU and memory requests with a policy (Kyverno, Gatekeeper) or a namespace LimitRange.
  • Keep the API endpoint subnet → worker/pod subnet rules in your NSG module and review them before hardening changes.
  • After each cluster upgrade, check oci ce cluster list-addons for add-ons not in ACTIVE state.