首页 > 其他 > 详细

安装kubectl top命令

时间:2020-09-17 09:24:36      阅读:263      评论:0      收藏:0      [点我收藏+]
背景:kubectl top命令可以查看node或者pod的cpu和内存的使用情况,所以我们安装kubectl top命令,这里我使用helm 安装,具体步骤如下:
1、首先添加helm 仓库
helm repo add bitnami https://charts.bitnami.com/bitnami
2、在仓库里搜索chart名字

[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%     

安装kubectl top命令

原文:https://blog.51cto.com/riverxyz/2534245

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!