在新版的Kubernetes中系统资源的采集均使用Metrics-Server,可以通过Metrics采集节点和Pod的内存、磁盘、CPU和网络的使用率。

1 wget 下载

cd /opt/kubernetes/addons
wget https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.6.1/components.yaml

2 增加内容

vim /opt/kubernetes/addons/components.yaml

- --kubelet-insecure-tls
- --requestheader-client-ca-file=/opt/kubernetes/pki/front-proxy-ca.pem
- --requestheader-username-headers=X-Remote-User
- --requestheader-group-headers=X-Remote-Group
- --requestheader-extra-headers-prefix=X-Remote-Extra-
image: swr.cn-north-1.myhuaweicloud.com/huaxiayuyi/metrics-server:v0.6.1


- name: ca-ssl
mountPath: /opt/kubernetes/pki

- name: ca-ssl
hostPath:
path: /opt/kubernetes/pki

3 经过修改的 components.yaml

查看代码

 

 

4 安装metrics server

kubectl apply -f /opt/kubernetes/addons/components.yaml

5 查看状态

kubectl top node

 

 

二、报错

此错误是 node 节点没有此证书

[root@kube-master01 ~]# kubectl logs  metrics-server-ff8979984-l7rmb -n kube-system
Error: unable to create request header authentication config: open /opt/kubernetes/pki/front-proxy-ca.pem: no such file or directory
...
panic: unable to create request header authentication config: open /opt/kubernetes/pki/front-proxy-ca.pem: no such file or directory

goroutine 1 [running]:
main.main()
	/go/src/sigs.k8s.io/metrics-server/cmd/metrics-server/metrics-server.go:37 +0xa5

# 解决
scp /opt/kubernetes/pki/front-proxy-ca.pem root@192.168.80.23:/opt/kubernetes/pki/
scp /opt/kubernetes/pki/front-proxy-ca.pem root@192.168.80.24:/opt/kubernetes/pki/