You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes自动扩缩容不生效,HPA目标显示<unknown>求助

Troubleshooting HPA Showing & Not Scaling

Hey there! I’ve helped tons of Kubernetes newbies work through this exact HPA issue, so let’s break down what’s likely going on and how to fix it.

1. Check if Metrics Server is Running (Most Common Culprit)

HPA v1 (which you’re using with autoscaling/v1) relies on CPU metrics, and the Metrics Server is the core component that collects and exposes these metrics to the cluster. If it’s missing or broken, HPA can’t get the data it needs, hence the <unknown> target.

  • First, verify if Metrics Server is deployed:
    kubectl get pods -n kube-system | grep metrics-server
    
  • If you don’t see any pods here, deploy it. For Minikube, you can enable it with minikube addons enable metrics-server. For other clusters, use kubectl apply with the official Metrics Server manifest.
  • If the pod exists but isn’t in Running state, check its logs for errors:
    kubectl logs <metrics-server-pod-name> -n kube-system
    
    A common fix here is adding the --kubelet-insecure-tls flag to the Metrics Server container (for clusters with self-signed Kubelet certificates) to bypass TLS validation.

2. Ensure Your Deployment Has CPU Requests

HPA calculates CPU usage as a percentage of the requested CPU for your pods. If your php-apache Deployment doesn’t define resources.requests.cpu, HPA has no baseline to calculate against, so it shows <unknown>.

  • Check your Deployment’s resource settings:

    kubectl describe deployment php-apache
    

    Look for the Resources section—you should see something like:

    Requests:
    cpu: 200m

  • If it’s missing, update your Deployment to add the CPU request:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: php-apache
    spec:
      template:
        spec:
          containers:
          - name: php-apache
            image: k8s.gcr.io/hpa-example
            resources:
              requests:
                cpu: "200m" # Add this line
              limits:
                cpu: "500m"
    

    Apply the update with kubectl apply -f <your-updated-deployment.yaml>.

3. Verify HPA is Linked to the Correct Target

Double-check that your HPA is pointing to the right Deployment (not a Pod, Service, or other resource). Autoscaling/v1 only supports Deployments, ReplicaSets, and ReplicationControllers.

  • Inspect your HPA configuration:

    kubectl describe hpa php-apache
    

    Look for the TargetRef section—it should match:

    TargetRef:
    API Version: apps/v1
    Kind: Deployment
    Name: php-apache

  • If the target is incorrect, re-create the HPA with the right reference.

4. Wait for Metrics to Be Collected

Sometimes Metrics Server needs a minute or two to start collecting data from your pods. After fixing the above steps, wait 2-3 minutes, then check if metrics are available:

kubectl top pods

If you see CPU usage for your php-apache pods, HPA should start showing the target value instead of <unknown>.

5. Generate Load to Trigger Scaling

Once HPA is working, you need to create load on the php-apache service to hit the CPU threshold (default is 50% in the official example). Run this command to generate continuous traffic:

kubectl run -i --tty load-generator --rm --image=busybox:1.28 --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"

After a minute or so, check the HPA status with kubectl get hpa—you should see the replica count increase as CPU usage rises.


内容的提问来源于stack exchange,提问作者Matt The Ninja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:51:28