0

按照此处的示例https://kubernetes.io/docs/tasks/run-application/horizo​​ntal -pod-autoscale-walkthrough/#autoscaling-on-metrics-not-related-to-kubernetes-objects ,我创建了安装的指标-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%

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

来自 metrics-server 的日志

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
4

2 回答 2

1

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

于 2020-11-04T21:24:39.233 回答
0

使用此版本的指标服务器

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

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

随着负载的增加,它会增加 pod 的数量

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

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

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

于 2021-08-18T19:06:38.427 回答