官网:GitHub - kubernetes-sigs/metrics-server: Scalable and efficient source of container resource metrics for Kubernetes built-in autoscaling pipelines.
metrics-server可以用来收集集群中的资源使用情况,搭配HPA Pod控制器使用
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/high-availability-1.21+.yaml
注意事项:
如果需要忽略 Kubelet certificate ,name只需要在 deployment 的containers.args 中加上 –kubelet-insecure-tls 即可
如果在国内,需要将镜像仓库更改为国内的源,例如阿里云的,例如将 8s.gcr.io/metrics-server/metrics-server 更改为 registry.aliyuncs.com/google_containers/metrics-server
需要关注k8s 和 metrics-server 版本对应关系,高版本的server可能不兼容低版本的k8s集群
需要确认最新 components.yaml 中授权是不是满足需求
下载下来上传到linux上进行部署
[root@master k8s]# vim ms.yaml
按图中添加下面选项
hostNetwork: true
image: bitnami/metrics-server:0.6.2
# registry.aliyuncs.com/google_containers/metrics-server:v0.6.1 不确定可以不可以使用
args:
- --kubelet-insecure-tls # 生产环境不推荐,这是忽略ca检测
- --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP
[root@master k8s]# kubectl apply -f ms.yaml
serviceaccount/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
service/metrics-server created
deployment.apps/metrics-server created
poddisruptionbudget.policy/metrics-server created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
[root@master k8s]# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-5bbd96d687-2s9q9 1/1 Running 0 2d7h
coredns-5bbd96d687-tvlzm 1/1 Running 0 9d
etcd-master 1/1 Running 0 9d
kube-apiserver-master 1/1 Running 0 9d
kube-controller-manager-master 1/1 Running 0 9d
kube-proxy-b8mzd 1/1 Running 0 9d
kube-proxy-g6q8z 1/1 Running 3 (2d7h ago) 9d
kube-proxy-trzb9 1/1 Running 2 (3d10h ago) 9d
kube-scheduler-master 1/1 Running 0 9d
metrics-server-6b5d469648-4vmvp 1/1 Running 0 6m39s
metrics-server-6b5d469648-hgr6q 1/1 Running 0 6m39s
注意: kubeadm 方式部署的话,在/etc/kubernetes/manifests/kube-apiserver.yaml修改
增加这一句话 - --enable-aggregator-routing=true 开启路由
二进制部署的话
`
vi /opt/kubernetes/cfg/kube-apiserver.conf
...
--requestheader-client-ca-file=/opt/kubernetes/ssl/ca.pem
--proxy-client-cert-file=/opt/kubernetes/ssl/server.pem
--proxy-client-key-file=/opt/kubernetes/ssl/server-key.pem
--requestheader-allowed-names=kubernetes
--requestheader-extra-headers-prefix=X-Remote-Extra-
--requestheader-group-headers=X-Remote-Group
--requestheader-username-headers=X-Remote-User
--enable-aggregator-routing=true
...
写的很简单,但是非常实用
如果kubectl top nodes 失败的话,首先看下metrics-server的日志,若果没有报错的话那就看下kube-apiserver的日志,这两个肯定有一个是报错的
基本上这块就是权限控制的问题导致的,如果搞不定的话,那就kubectl delete -f 刚才下载的yaml文件,然后看下面的链接,百分之百能搞定
Kubernetes 部署 Metrics Server 获取集群指标数据 | 小豆丁技术栈