k8s dashboar上的pod的资源监控都是空的
倒腾一波发现原来少个插件。
写在前面
在新版的K8S中,系统资源的采集均使用Metrics-Server服务,可以通过Metrics-Server服务采集节点和Pod的内存、磁盘、CPU和网络的使用率等信息。
说的具体点:新版K8S资源使用情况的度量(如容器的 CPU 和内存使用)可以通过 Metrics API 获取。
注意:
- Metrics API 只可以查询当前的度量数据,并不保存历史数据
- Metrics API URI 为 /apis/metrics.k8s.io/,在 k8s.io/metrics维护
- 必须部署 metrics-server 才能使用该 API,metrics-server 通过调用 Kubelet Summary API 获取数据
部署Metrics-Server服务
1.下载并解压Metrics-Server
https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz tar -zxvf v0.3.6.tar.gz
2.修改Metrics-Server配置文件
cd metrics-server-0.3.6/deploy/1.8+/ vim metrics-server-deployment.yaml
vim metrics-server-deployment.yaml文件原有的内容如下所示。
--- apiVersion: v1 kind: ServiceAccount metadata: name: metrics-server namespace: kube-system --- apiVersion: apps/v1 kind: Deployment metadata: name: metrics-server namespace: kube-system labels: k8s-app: metrics-server spec: selector: matchLabels: k8s-app: metrics-server template: metadata: name: metrics-server labels: k8s-app: metrics-server spec: serviceAccountName: metrics-server volumes: # mount in tmp so we can safely use from-scratch images and/or read-only containers - name: tmp-dir emptyDir: {} containers: - name: metrics-server image: k8s.gcr.io/metrics-server-amd64:v0.3.6 imagePullPolicy: Always volumeMounts: - name: tmp-dir mountPath: /tmp
修改后的文件内容如下所示。
--- apiVersion: v1 kind: ServiceAccount metadata: name: metrics-server namespace: kube-system --- apiVersion: apps/v1 kind: Deployment metadata: name: metrics-server namespace: kube-system labels: k8s-app: metrics-server spec: selector: matchLabels: k8s-app: metrics-server template: metadata: name: metrics-server labels: k8s-app: metrics-server spec: serviceAccountName: metrics-server volumes: # mount in tmp so we can safely use from-scratch images and/or read-only containers - name: tmp-dir emptyDir: {} containers: - name: metrics-server # 修改image 和 imagePullPolicy image: mirrorgooglecontainers/metrics-server-amd64:v0.3.6 imagePullPolicy: IfNotPresent # 新增command配置 command: - /metrics-server - --kubelet-insecure-tls - --kubelet-preferred-address-types=InternalDNS,InternalIP,ExternalDNS,ExternalIP,Hostname volumeMounts: - name: tmp-dir mountPath: /tmp # 新增resources配置 resources: limits: cpu: 300m memory: 200Mi requests: cpu: 200m memory: 100Mi
修改完metrics-server-deployment.yaml文件后保存退出。
3.安装Metrics-Server
执行如下命令安装Metrics-Server。
kubectl apply -f metrics-server-0.3.6/deploy/1.8+/
-- 2022年4月25日13:08:20 ,注意这里一定是要把整个目录下的yaml apply一遍,而不是apply metrics-server-deployment.yaml.否则会有很奇怪的授权错误.
Unable to get configmap/extension-apiserver-authentication in kube-system. Usually fixed by 'kubectl create rolebinding -n kubetension-apiserver-authentication-reader --serviceaccount=YOUR_NS:YOUR_SA' configmaps "extension-apiserver-authentication" is forbidden: User "system:serviceaccount:kube-system:metrics-server" cannot get resource "configmaps" in API group "" in the namespace "kube-system
4.查看node信息
安装完Metrics-Server之后,查看node信息,如下所示。
[root@hadoop100 ~]#kubectl top nodes NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% hadoop100 367m 18% 1260Mi 72% hadoop101 153m 7% 953Mi 54% hadoop102 167m 8% 1016Mi 58%
可以看到,使用Metrics-Server收集到节点信息,说明Metrics-Server安装成功。
dashboard上也有啦