helm repo add bitnami https://charts.bitnami.com/bitnami
[root@master base]# helm search repo metrics-server
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/metrics-server 4.3.1 0.3.7 Metrics Server is a cluster-wide aggregator of ...
3、使用helm安装
[root@master base]# helm status metrics-server -n kube-system
NAME: metrics-server
LAST DEPLOYED: Wed Sep 16 16:59:01 2020
NAMESPACE: kube-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
** Please be patient while the chart is being deployed **
The metric server has been deployed.
In a few minutes you should be able to list metrics using the following
command:
kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes"
4、安装完按他提示的命令查询一下,以验证安装是否成功,如果安装成功会返回一堆值,如果安装不成功使用helm merics-server查询日志
[root@master base]# 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":"10.1.6.100","selfLink":"/apis/metrics.k8s.io/v1beta1/nodes/10.1.6.100","creationTimestamp":"2020-09-16T09:27:58Z"},"timestamp":"2020-09-16T09:27:01Z","window":"30s","usage":{"cpu":"223236233n","memory":"4363840Ki"}},{"metadata":{"name":"10.1.6.101","selfLink":"/apis/metrics.k8s.io/v1beta1/nodes/10.1.6.101","creationTimestamp":"2020-09-16T09:27:58Z"},"timestamp":"2020-09-16T09:26:58Z","window":"30s","usage":{"cpu":"1084386738n","memory":"5706400Ki"}},{"metadata":{"name":"10.1.6.99","selfLink":"/apis/metrics.k8s.io/v1beta1/nodes/10.1.6.99","creationTimestamp":"2020-09-16T09:27:58Z"},"timestamp":"2020-09-16T09:27:03Z","window":"30s","usage":{"cpu":"740398897n","memory":"8287948Ki"}}]}
5、安装完后查看日志会有报错提示
E0916 09:08:22.238571 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/dashboard-metrics-scraper-c79c65bb7-xpqqb: no metrics known for pod
E0916 09:08:23.506206 1 manager.go:111] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:10.1.6.101: unable to fetch metrics from Kubelet 10.1.6.101 (10.1.6.101): Get https://10.1.6.101:10250/stats/summary?only_cpu_and_memory=true: x509: certificate signed by unknown authority, unable to fully scrape metrics from source kubelet_summary:10.1.6.99: unable to fetch metrics from Kubelet 10.1.6.99 (10.1.6.99): Get https://10.1.6.99:10250/stats/summary?only_cpu_and_memory=true: x509: certificate signed by unknown authority, unable to fully scrape metrics from source kubelet_summary:10.1.6.100: unable to fetch metrics from Kubelet 10.1.6.100 (10.1.6.100): Get https://10.1.6.100:10250/stats/summary?only_cpu_and_memory=true: x509: certificate signed by unknow
6、这时需要修改deploy的一个值
kubectl -n kube-system edit deployments.apps metrics-server
spec:
containers:
- command:
- metrics-server
- --secure-port=8443
**- --kubelet-insecure-tls**
7、修改后就可以使用kubectl top node查看了
[root@master base]# kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
10.1.6.100 222m 1% 4264Mi 14%
10.1.6.101 1081m 9% 5579Mi 18%
10.1.6.99 703m 5% 8120Mi 27%
原文:https://blog.51cto.com/riverxyz/2534245