Kubernetes HPA显示<unknown>问题求助:前端服务无法获取有效指标值
<unknown> When Metrics Server Isn't Ready Let’s break down what’s going on here and fix your HPA issue step by step:
The core problem is clear: your Metrics Server deployment isn’t ready (shows 0/1 in your kubectl get deployment output). HPA depends entirely on Metrics Server to pull CPU/memory usage data from pods—if Metrics Server can’t run properly, HPA has no metrics to display, hence the <unknown> value.
Here’s how to resolve this:
1. Diagnose Why Metrics Server Is Failing
First, check the logs of the Metrics Server pod to uncover the root cause:
kubectl logs deployment/metrics-server -n kube-system
Common issues here include:
- Certificate validation errors (most local/private clusters use self-signed certificates for kubelet)
- Network connectivity problems with the Kubernetes API Server
- Missing required startup flags for Metrics Server
2. Fix the Metrics Server Deployment
The most frequent fix for a stuck Metrics Server is adding a flag to skip kubelet certificate verification (safe for non-production environments; adjust certificate settings properly for production):
- Edit the Metrics Server deployment:
kubectl edit deployment metrics-server -n kube-system - Find the
argssection under themetrics-servercontainer, and add the--kubelet-insecure-tlsflag:args: - --cert-dir=/tmp - --secure-port=4443 - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname - --kubelet-use-node-status-port - --kubelet-insecure-tls # Add this line - Save and exit the editor—Kubernetes will automatically restart the Metrics Server pod.
3. Verify Metrics Server Is Working
Wait 30 seconds, then check if the deployment is ready:
kubectl get deployment metrics-server -n kube-system
Once it shows 1/1 Ready, confirm it can fetch metrics:
# Check node-level metrics kubectl top nodes # Check metrics for your udagram-frontend pods kubectl top pods
If these commands return valid CPU/memory values, Metrics Server is functioning correctly.
4. Recheck Your HPA Status
Give HPA a minute to pull the new metrics, then run:
kubectl describe hpa udagram-frontend
You should now see actual CPU usage percentages instead of <unknown>.
A quick note: Your udagram-frontend deployment is correctly configured with resources.requests.cpu—this is a required setting for HPA to calculate usage percentages, so you don’t need to adjust anything there.
内容的提问来源于stack exchange,提问作者Oussama Bouchikhi

