kubernetes runtime_error ai_generated true

无法获取 CPU 利用率:无法获取资源 CPU 的指标:无法从资源指标 API 获取指标:服务器找不到请求的资源(get pods.metrics.k8s.io)

failed to get cpu utilization: unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)

ID: kubernetes/horizontal-pod-autoscaler-missing-metrics

其他格式: JSON · Markdown 中文 · English
92%修复率
90%置信度
1证据数
2023-11-01首次发现

版本兼容性

版本状态引入弃用备注
kubernetes 1.27 active
metrics-server 0.6 active
metrics-server 0.7 active

根因分析

metrics-server(或自定义指标适配器)未安装或未正常运行,导致 Horizontal Pod Autoscaler 无法检索 CPU/内存指标。

English

The metrics-server (or custom metrics adapter) is not installed or not functioning, so the Horizontal Pod Autoscaler cannot retrieve CPU/memory metrics.

generic

官方文档

https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-metrics-apis

解决方案

  1. 使用 `kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml` 部署 metrics-server。验证其运行:`kubectl get pods -n kube-system | grep metrics-server`。检查日志错误:`kubectl logs -n kube-system deployment/metrics-server`。
  2. 运行 `kubectl get apiservices.apiregistration.k8s.io | grep metrics` 查看 `v1beta1.metrics.k8s.io` 或 `v1beta1.custom.metrics.k8s.io` 是否可用。如果不可用,确保 metrics-server 部署健康且其服务端点可达。

无效尝试

常见但无效的做法:

  1. 95% 失败

    Changing the target doesn't fix the missing metrics API; the HPA still can't get any data.

  2. 90% 失败

    The HPA controller is not the source of metrics; it relies on the metrics API which is unavailable.

  3. 50% 失败

    Conflicting adapters can cause API registration issues; the correct approach is to ensure only one metrics provider is active.