Kubernetes 指标服务器不提供所有指标或扩展 HPA



下面的例子https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-在与kubernetes对象无关的度量上,我创建了已安装的度量服务器,并对其进行了如下修改:

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

运行顶部节点可以工作,但顶部吊舱不能

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%

顶部吊舱返回错误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

当Docker 19.03在Kubernetes 1.19版本上使用时,与此上游问题有关的问题得到了解决:https://github.com/kubernetes/kubernetes/issues/94281

使用此版本的度量服务器

git clone https://github.com/kodekloudhub/kubernetes-metrics-server
kubectl apply -f kubernetes-metrics-server

然后按照本链接中提到的相同说明进行操作

随着负载的增加,它将增加吊舱的数量

但是我注意到自动缩放器不会在负载停止时缩小部署。它可能需要一些时间,直到它再次缩小

注意:此版本的度量服务器只能在开发或学习环境中使用。

我使用Katakoda环境来测试答案。

相关内容

  • 没有找到相关文章

最新更新