本笔记将记录如何部署 Metrics Server 组建。
Kubernetes Cluster v1.16
环境要求
Metrics Server 对网络和集群有特殊要求。这样要求在某些集群里不是默认配置,所以要先确认是否满足要求。
# 自从用了 Kubernetes 以后,就有看不完的文档和资源。在很多教程中,都是直接 apply 就可以,反正能用,说明这些依赖在大多数集群里都开启了。但是即使知道这样能够完成部署任务,我们还是得看文档。不看这些文档,就不知道这些东西是怎么工作的,故障时就难以排查。
Metrics Server must be reachable from kube-apiserver
The kube-apiserver must be correctly configured to enable an aggregation layer
Configure the Aggregation Layer - Kubernetes
检查 /etc/kubernetes/manifests/kube-apiserver.yaml 选项,默认已经开启。
Nodes must have kubelet authorization configured to match Metrics Server configuration
Container runtime must implement a container metrics RPCs
安装组建
第二步、修改配置信息
下载 components.yaml 文件,对其进行修改:
1)我们需要修改在 YAML 文件中的镜像地址,使用私有镜像仓库;
2)添加 --kubelet-preferred-address-types=InternalIP 与 --kubelet-insecure-tls 选项;
第三步、应用配置文件
kubectl apply -f "/path/to/components.yaml"
常见错误汇总
Metrics not available for pod
# kubectl top -n kube-system pod W0702 10:48:07.400630 6619 top_pod.go:266] Metrics not available for pod kube-system/coredns-58cc8c89f4-6czm4, age: 4267h8m49.400600321s error: Metrics not available for pod kube-system/coredns-58cc8c89f4-6czm4, age: 4267h8m49.400600321s
通过添加 --kubelet-preferred-address-types=InternalIP 与 --kubelet-insecure-tls 选项解决;
unable to fetch pod metrics for pod
E0702 02:39:09.777832 1 reststorage.go:160] unable to fetch pod metrics for pod default/counter: no metrics known for pod E0702 02:39:09.777843 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/etcd-k8s-master-02: no metrics known for pod E0702 02:39:09.777863 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/fluentd-p6d29: no metrics known for pod E0702 02:39:09.777874 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/kube-proxy-xdh2z: no metrics known for pod E0702 02:39:09.777885 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/etcd-k8s-master-01: no metrics known for pod E0702 02:39:09.777900 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/kube-proxy-jrpnd: no metrics known for pod
通过添加 --kubelet-preferred-address-types=InternalIP 与 --kubelet-insecure-tls 选项解决;
相关文章
参考文献
Kubernetes metrics-server Installation
Installing the Kubernetes Metrics Server
Kubernetes Metrics unable to fetch pod/node metrics - Stack Overflow