Kubernetes 指标服务器不提供所有指标或扩展 HPA
Posted
技术标签:
【中文标题】Kubernetes 指标服务器不提供所有指标或扩展 HPA【英文标题】:Kubernetes metrics-server doesn't provide all metrics or scale HPA 【发布时间】:2021-02-17 10:20:30 【问题描述】:按照此处https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-metrics-not-related-to-kubernetes-objects 的示例,我创建了已安装的metrics-server 并对其进行了如下修改:
spec:
containers:
- command:
- metrics-server
- --secure-port=8443
- --kubelet-insecure-tls=true
- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
image: docker.io/bitnami/metrics-server:0.3.7-debian-10-r89
imagePullPolicy: IfNotPresent
name: metrics-server
ports:
- containerPort: 8443
name: https
protocol: TCP
resources:
查询时会列出我的节点:
kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes"
"kind":"NodeMetricsList","apiVersion":"metrics.k8s.io/v1beta1","metadata":"selfLink":"/apis/metrics.k8s.io/v1beta1/nodes","items":["metadata":"name":"eo-test-metrics-35lks","selfLink":"/apis/metrics.k8s.io/v1beta1/nodes/eo-test-metrics-35lks","creationTimestamp":"2020-11-04T04:05:58Z","timestamp":"2020-11-04T04:05:28Z","window":"30s","usage":"cpu":"770120208n","memory":"934476Ki","metadata":"name":"eo-test-metrics-35lkp","selfLink":"/apis/metrics.k8s.io/v1beta1/nodes/eo-test-metrics-35lkp","creationTimestamp":"2020-11-04T04:05:58Z","timestamp":"2020-11-04T04:05:25Z","window":"30s","usage":"cpu":"483763591n","memory":"850756Ki"]
但是,HPA 目标仍然“未知”:
kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
php-apache Deployment/php-apache <unknown>/50% 1 10 1 31m
运行***节点有效,但*** pod 无效
kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
eo-test-metrics-35lkp 93m 4% 934Mi 30%
eo-test-metrics-35lks 166m 8% 1053Mi 33%
Top pods 返回错误error: Metrics not available
:
kubectl top pods
W1104 11:19:27.854485 62798 top_pod.go:266] Metrics not available for pod default/php-apache-d4cf67d68-blt2c, age: 13h1m51.854463s
error: Metrics not available for pod default/php-apache-d4cf67d68-blt2c, age: 13h1m51.854463s
这是在 Kubernetes 服务器版本 v1.19.3
和指标服务器版本 0.3.6
上
来自度量服务器的日志
E1104 21:21:56.496129 1 reststorage.go:160] unable to fetch pod metrics for pod default/php-apache-d4cf67d68-blt2c: no metrics known for pod
E1104 21:22:10.945091 1 reststorage.go:160] unable to fetch pod metrics for pod default/php-apache-d4cf67d68-blt2c: no metrics known for pod
E1104 21:22:26.496814 1 reststorage.go:160] unable to fetch pod metrics for pod default/php-apache-d4cf67d68-blt2c: no metrics known for pod
【问题讨论】:
【参考方案1】:当 Docker 19.03 用于 Kubernetes 版本 1.19 时,与此上游问题相关的问题已解决:https://github.com/kubernetes/kubernetes/issues/94281
【讨论】:
【参考方案2】:使用此版本的指标服务器
git clone https://github.com/kodekloudhub/kubernetes-metrics-server
kubectl apply -f kubernetes-metrics-server
然后按照this link中提到的相同说明进行操作
它会随着负载的增加而增加 pod 的数量
但是我注意到自动缩放器不会在负载停止时缩减部署。可能需要一些时间才能再次缩小规模
注意:此版本的指标服务器只能在开发或学习环境中使用。
我使用Katakoda environment 来测试答案。
【讨论】:
以上是关于Kubernetes 指标服务器不提供所有指标或扩展 HPA的主要内容,如果未能解决你的问题,请参考以下文章
在 prometheus 中排除 Kubernetes Metrics 监控
避免 Prometheus 调用所有 k8s 服务实例(只有一个,应用范围的指标收集)
将 kubernetes(GKE) 服务层指标发送到 GCP 负载均衡器