k8s小工具之kubectl-mytop插件

本文涉及的产品
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
可观测监控 Prometheus 版,每月50GB免费额度
全局流量管理 GTM,标准版 1个月
简介: Kubectl-mytop是一个基于metrics-server组件做指标展示的命令行工具,综合kubectl top以及kubectl describe的展示能力,可以提供Kubernetes集群中node以及pod资源请求、资源限制、资源利用率、以及pod数量做排序展示。Kubectl-mytop插件的目的在于弥补当前常用k8s监控工具的不足,便于如资源不均,调度不均,使用率不均等问题的分析定位。如指定node后,可以查看这个node上所有的pod的request,limit,util资源使用等信息并排序输出,支持指定不同namespace的相同的pod label的资源展示,以及过滤指定

kubectl-mytop介绍

Kubectl-mytop是一个基于metrics-server组件做指标展示的命令行工具,综合kubectl top以及kubectl describe的展示能力,可以提供Kubernetes集群中node以及pod资源请求、资源限制、资源利用率、以及pod数量做排序展示。Kubectl-mytop插件的目的在于弥补当前常用k8s监控工具的不足,便于如资源不均,调度不均,使用率不均等问题的分析定位。如指定node后,可以查看这个node上所有的pod的request,limit,util资源使用等信息并排序输出,支持指定不同namespace的相同的pod label的资源展示,以及过滤指定节点池id的资源展示

当前监控工具的不足

  1. 阿里云ACK控制台:

在阿里云ack控制台,点到节点里面,可以看到1个节点上所有的pod信息,当需要多个节点对比时,易用性不佳

  1. Prometheus:

Pod级别的监控通常是按照namespace及deployment分开展示,若想查看特定节点上所有pod的资源使用情况,或者相同label不同的deployment监控时 Promethes通用大盘无法直观显示,且很多集群没有预装prometheus组件。同时promethus组件本身也有一定的资源开销。若只是查询基础资源使用/占用情况,cli方式会更便捷。

  1. kubectl top pod/node

无法统计特定节点所有pod资源信息

```
[root@iZ2ze1mh3b0oot4j1m3uhsZ ~]# kubectl top pods
NAME                                             CPU(cores)   MEMORY(bytes)   
aestools-79999865cc-w2rsd                        0m           1Mi             
aestools-onlyperf-6f779888f7-pqtpr               0m           31Mi            
alpine-74c4d47df8-rdpq4                          883m         22Mi            
cpu-static-5d88d58877-j9jvl                      0m           1Mi             
golang-7cdc688b6-2mbrq                           0m           0Mi             
hello-pod                                        0m           5Mi             
java-php-perf-arthas-84b5799f67-7hb8t            0m           1Mi             
jen-7ffb5fd6fc-d5qcw                             1m           299Mi           
multi-containers-6695d87b75-2vkf4                0m           6Mi             
my-gotools-5bc6dfcd75-j4tmk                      0m           2Mi             
my-nettools-multicluster-test-75497d67fb-fmskd   1m           3Mi             
my-nettools-primary-8584bffdf5-9lwh6             1m           6Mi             
my-nettools-primary-8584bffdf5-b65fr             1m           5Mi             
my-wordpress-85d86fb874-s9x54                    1m           73Mi            
php-perf-5487b88c4-ssk2q                         0m           0Mi                          
[root@iZ2ze1mh3b0oot4j1m3uhsZ ~]# kubectl top nodes
NAME                        CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
cn-beijing.192.168.0.17     427m         11%    4974Mi          76%       
cn-beijing.192.168.0.246    724m         18%    4302Mi          66%       
cn-beijing.192.168.66.175   148m         3%     4096Mi          63%       
cn-beijing.192.168.88.154   197m         2%     5600Mi          39%       
cn-beijing.192.168.88.156   1353m        17%    8822Mi          62%       
cn-beijing.192.168.88.243   455m         11%    5178Mi          80% 
```
  1. kubectl describe node

无法显示pod资源利用率,且无法综合所有节点信息同时显示,指标展示不够直观。

```
......
Non-terminated Pods:          (11 in total)
  Namespace                   Name                                                      CPU Requests  CPU Limits   Memory Requests  Memory Limits  AGE
  ---------                   ----                                                      ------------  ----------   ---------------  -------------  ---
  default                     aestools-79999865cc-w2rsd                                 250m (3%)     0 (0%)       512Mi (3%)       0 (0%)         14d
  default                     cpu-static-5d88d58877-j9jvl                               2 (25%)       2 (25%)      512Mi (3%)       512Mi (3%)     14d
  kube-system                 ack-node-problem-detector-daemonset-nwvxd                 100m (1%)     1 (12%)      200Mi (1%)       1Gi (7%)       109d
  kube-system                 appcenter-7c7bbb5f76-d7dxf                                0 (0%)        0 (0%)       0 (0%)           0 (0%)         394d
  kube-system                 csi-plugin-tznkk                                          130m (1%)     2 (25%)      176Mi (1%)       4Gi (28%)      333d
  kube-system                 kube-proxy-worker-qjm5c                                   0 (0%)        0 (0%)       0 (0%)           0 (0%)         475d
  kube-system                 logtail-ds-6t6sp                                          100m (1%)     500m (6%)    256Mi (1%)       1Gi (7%)       113d
  kube-system                 nginx-ingress-controller-57cb45dd78-l5gx2                 100m (1%)     0 (0%)       90Mi (0%)        0 (0%)         14d
  kube-system                 node-local-dns-nnbjc                                      25m (0%)      0 (0%)       5Mi (0%)         1Gi (7%)       27d
  kube-system                 terway-eniip-m9877                                        350m (4%)     1100m (14%)  200Mi (1%)       256Mi (1%)     214d
  monitoring                  ack-prometheus-operator-prometheus-node-exporter-fhzrx    0 (0%)        0 (0%)       0 (0%)           0 (0%)         109d
......
```

mytop使用典型场景:

  1. 可同时显示node以及pod资源请求、限制、利用率
  2. 按照指标数值排序显示
  3. 显示节点上pod数量与上限
  4. 按照pod标签、namespace标签、namespace、节点标签过滤显示
  5. 输出格式可选table、json、yaml

Github地址:

https://github.com/mYu4N/kubectl-mytop

安装:

wget https://raw.githubusercontent.com/mYu4N/kubectl-mytop/master/kubectl-mytop -O /usr/local/bin/kubectl-mytop 
chmod u+x /usr/local/bin/kubectl-mytop

使用:

默认情况下,kubectl mytop将输出一个节点列表,其中包含CPU和内存资源的总请求以及在其上运行的所有pod的限制(类似describe node的资源输出)。对于具有多个节点的集群,第一行还将包括集群范围内的总计(sum)。如下所示:

```
% kubectl mytop                         
NODE                       | CPU REQUESTS  | CPU LIMITS     | MEMORY REQUESTS  | MEMORY LIMITS
*                          | 17790m (56%)  | 92600m (294%)  | 20271Mi (37%)    | 130905Mi (240%)
cn-beijing.192.168.0.17    | 2475m (65%)   | 16000m (421%)  | 3995Mi (61%)     | 25354Mi (391%)
cn-beijing.192.168.0.246   | 2855m (71%)   | 11100m (277%)  | 3307Mi (51%)     | 13532Mi (208%)
cn-beijing.192.168.66.175  | 2755m (68%)   | 22600m (565%)  | 2822Mi (43%)     | 38243Mi (590%)
cn-beijing.192.168.88.154  | 3055m (39%)   | 6600m (84%)    | 1951Mi (13%)     | 7936Mi (55%)
cn-beijing.192.168.88.156  | 4615m (59%)   | 24100m (308%)  | 5586Mi (39%)     | 32399Mi (227%)
cn-beijing.192.168.88.243  | 2035m (50%)   | 12200m (305%)  | 2611Mi (40%)     | 13442Mi (207%)
```

展示pod资源情况:

可以使用-p 或者 --pods 参数, 会展示pod级别的request limit,当节点或者pod比较多的时候,输出较多阅读有所不便,如下所示:

```
% kubectl mytop  --pods -n default
NODE                       | POD                                             | CPU REQUESTS  | CPU LIMITS   | MEMORY REQUESTS  | MEMORY LIMITS
*                          | *                                               | 6000m (19%)   | 6500m (20%)  | 8192Mi (15%)     | 6144Mi (11%)
                           |                                                 |               |              |                  | 
cn-beijing.192.168.0.17    | *                                               | 750m (19%)    | 1000m (26%)  | 1536Mi (23%)     | 1024Mi (15%)
cn-beijing.192.168.0.17    | golang-7cdc688b6-2mbrq                          | 250m (6%)     | 0Mi (0%)     | 512Mi (7%)       | 0Mi (0%)
cn-beijing.192.168.0.17    | my-gotools-5bc6dfcd75-j4tmk                     | 250m (6%)     | 0Mi (0%)     | 512Mi (7%)       | 0Mi (0%)
cn-beijing.192.168.0.17    | my-nettools-primary-8584bffdf5-9lwh6            | 250m (6%)     | 1000m (26%)  | 512Mi (7%)       | 1024Mi (15%)
                           |                                                 |               |              |                  | 
cn-beijing.192.168.0.246   | *                                               | 1000m (25%)   | 1500m (37%)  | 1536Mi (23%)     | 2560Mi (39%)
cn-beijing.192.168.0.246   | java-php-perf-arthas-84b5799f67-7hb8t           | 500m (12%)    | 1000m (25%)  | 1024Mi (15%)     | 2048Mi (31%)
cn-beijing.192.168.0.246   | multi-containers-6695d87b75-2vkf4               | 500m (12%)    | 500m (12%)   | 512Mi (7%)       | 512Mi (7%)
                           |                                                 |               |              |                  | 
cn-beijing.192.168.66.175  | *                                               | 250m (6%)     | 1000m (25%)  | 512Mi (7%)       | 1024Mi (15%)
cn-beijing.192.168.66.175  | my-nettools-multicluster-test-75497d67fb-fmskd  | 250m (6%)     | 1000m (25%)  | 512Mi (7%)       | 1024Mi (15%)
                           |                                                 |               |              |                  | 
cn-beijing.192.168.88.154  | *                                               | 2250m (28%)   | 2000m (25%)  | 1024Mi (7%)      | 512Mi (3%)
cn-beijing.192.168.88.154  | aestools-79999865cc-w2rsd                       | 250m (3%)     | 0Mi (0%)     | 512Mi (3%)       | 0Mi (0%)
cn-beijing.192.168.88.154  | cpu-static-5d88d58877-j9jvl                     | 2000m (25%)   | 2000m (25%)  | 512Mi (3%)       | 512Mi (3%)
                           |                                                 |               |              |                  | 
cn-beijing.192.168.88.156  | *                                               | 1500m (19%)   | 1000m (12%)  | 3072Mi (21%)     | 1024Mi (7%)
cn-beijing.192.168.88.156  | aestools-onlyperf-6f779888f7-pqtpr              | 250m (3%)     | 0Mi (0%)     | 512Mi (3%)       | 0Mi (0%)
cn-beijing.192.168.88.156  | alpine-74c4d47df8-rdpq4                         | 250m (3%)     | 0Mi (0%)     | 512Mi (3%)       | 0Mi (0%)
cn-beijing.192.168.88.156  | hello-pod                                       | 0Mi (0%)      | 0Mi (0%)     | 0Mi (0%)         | 0Mi (0%)
cn-beijing.192.168.88.156  | my-nettools-primary-8584bffdf5-b65fr            | 250m (3%)     | 1000m (12%)  | 512Mi (3%)       | 1024Mi (7%)
cn-beijing.192.168.88.156  | my-wordpress-85d86fb874-s9x54                   | 250m (3%)     | 0Mi (0%)     | 512Mi (3%)       | 0Mi (0%)
cn-beijing.192.168.88.156  | php-perf-5487b88c4-ssk2q                        | 250m (3%)     | 0Mi (0%)     | 512Mi (3%)       | 0Mi (0%)
                           |                                                 |               |              |                  | 
cn-beijing.192.168.88.243  | *                                               | 250m (6%)     | 0Mi (0%)     | 512Mi (7%)       | 0Mi (0%)
cn-beijing.192.168.88.243  | jen-7ffb5fd6fc-d5qcw                            | 250m (6%)     | 0Mi (0%)     | 512Mi (7%)       | 0Mi (0%)
```

支持显示利用率:

使用参数 -u 或者 --util 支持显示节点级别的利用率,类似top node的功能, 该功能走的是metrics的指标,如下所示:

``` 
% kubectl mytop  --util
NODE                       | CPU REQUESTS  | CPU LIMITS     | CPU UTIL     | MEMORY REQUESTS  | MEMORY LIMITS    | MEMORY UTIL
*                          | 17790m (56%)  | 92600m (294%)  | 3051m (9%)   | 20271Mi (37%)    | 130905Mi (240%)  | 32066Mi (58%)
cn-beijing.192.168.0.17    | 2475m (65%)   | 16000m (421%)  | 390m (10%)   | 3995Mi (61%)     | 25354Mi (391%)   | 4211Mi (64%)
cn-beijing.192.168.0.246   | 2855m (71%)   | 11100m (277%)  | 516m (12%)   | 3307Mi (51%)     | 13532Mi (208%)   | 4375Mi (67%)
cn-beijing.192.168.66.175  | 2755m (68%)   | 22600m (565%)  | 211m (5%)    | 2822Mi (43%)     | 38243Mi (590%)   | 4132Mi (63%)
cn-beijing.192.168.88.154  | 3055m (39%)   | 6600m (84%)    | 207m (2%)    | 1951Mi (13%)     | 7936Mi (55%)     | 5480Mi (38%)
cn-beijing.192.168.88.156  | 4615m (59%)   | 24100m (308%)  | 1379m (17%)  | 5586Mi (39%)     | 32399Mi (227%)   | 8790Mi (61%)
cn-beijing.192.168.88.243  | 2035m (50%)   | 12200m (305%)  | 352m (8%)    | 2611Mi (40%)     | 13442Mi (207%)   | 5082Mi (78%)
```

支持显示可用资源:

使用  --available 可以查看节点可用资源,对规格感知问题导致会不太准确

```
% kubectl mytop  --available
NODE                       | CPU REQUESTS   | CPU LIMITS      | MEMORY REQUESTS  | MEMORY LIMITS
*                          | 13610m/31400m  | -61200m/31400m  | 34098Mi/54369Mi  | -76536Mi/54369Mi
cn-beijing.192.168.0.17    | 1325m/3800m    | -12200m/3800m   | 2488Mi/6483Mi    | -18871Mi/6483Mi
cn-beijing.192.168.0.246   | 1145m/4000m    | -7100m/4000m    | 3176Mi/6483Mi    | -7049Mi/6483Mi
cn-beijing.192.168.66.175  | 1245m/4000m    | -18600m/4000m   | 3650Mi/6472Mi    | -31771Mi/6472Mi
cn-beijing.192.168.88.154  | 4745m/7800m    | 1200m/7800m     | 12280Mi/14231Mi  | 6295Mi/14231Mi
cn-beijing.192.168.88.156  | 3185m/7800m    | -16300m/7800m   | 8645Mi/14231Mi   | -18168Mi/14231Mi
cn-beijing.192.168.88.243  | 1965m/4000m    | -8200m/4000m    | 3861Mi/6472Mi    | -6970Mi/6472Mi
```

支持显示pod的使用率

使用参数 --util--pods 时, 可以显示pod级别的util,类似top pod:

``` 
% kubectl mytop --pods --util -n default
NODE                       | POD                                             | CPU REQUESTS  | CPU LIMITS   | CPU UTIL    | MEMORY REQUESTS  | MEMORY LIMITS  | MEMORY UTIL
*                          | *                                               | 6000m (19%)   | 6500m (20%)  | 0Mi (0%)    | 8192Mi (15%)     | 6144Mi (11%)   | 0Mi (0%)
                           |                                                 |               |              |             |                  |                | 
cn-beijing.192.168.0.17    | *                                               | 750m (19%)    | 1000m (26%)  | 1m (0%)     | 1536Mi (23%)     | 1024Mi (15%)   | 26Mi (0%)
cn-beijing.192.168.0.17    | golang-7cdc688b6-2mbrq                          | 250m (6%)     | 0Mi (0%)     | 0m (0%)     | 512Mi (7%)       | 0Mi (0%)       | 3Mi (0%)
cn-beijing.192.168.0.17    | my-gotools-5bc6dfcd75-j4tmk                     | 250m (6%)     | 0Mi (0%)     | 0m (0%)     | 512Mi (7%)       | 0Mi (0%)       | 3Mi (0%)
cn-beijing.192.168.0.17    | my-nettools-primary-8584bffdf5-9lwh6            | 250m (6%)     | 1000m (26%)  | 1m (0%)     | 512Mi (7%)       | 1024Mi (15%)   | 21Mi (0%)
                           |                                                 |               |              |             |                  |                | 
......省略一万字
                           |                                                 |               |              |             |                  |                | 
cn-beijing.192.168.88.243  | *                                               | 250m (6%)     | 0Mi (0%)     | 1m (0%)     | 512Mi (7%)       | 0Mi (0%)       | 300Mi (4%)
cn-beijing.192.168.88.243  | jen-7ffb5fd6fc-d5qcw                            | 250m (6%)     | 0Mi (0%)     | 1m (0%)     | 512Mi (7%)       | 0Mi (0%)       | 300Mi (4%)
```

PS:节点跟pod的展示有所不同,节点是pod的sum值,过小的值也会导致数据失真

排序

可以指定不同的指标做排序,如下为节点 cpu的util的排序(总和值可以不看):

```
% kubectl mytop --util --sort cpu.util
NODE                       | CPU REQUESTS  | CPU LIMITS     | CPU UTIL     | MEMORY REQUESTS  | MEMORY LIMITS    | MEMORY UTIL
*                          | 17790m (56%)  | 92600m (294%)  | 5825m (18%)  | 20271Mi (37%)    | 130905Mi (240%)  | 32097Mi (59%)
cn-beijing.192.168.66.175  | 2755m (68%)   | 22600m (565%)  | 2852m (71%)  | 2822Mi (43%)     | 38243Mi (590%)   | 4134Mi (63%)
cn-beijing.192.168.88.156  | 4615m (59%)   | 24100m (308%)  | 1429m (18%)  | 5586Mi (39%)     | 32399Mi (227%)   | 8791Mi (61%)
cn-beijing.192.168.0.246   | 2855m (71%)   | 11100m (277%)  | 510m (12%)   | 3307Mi (51%)     | 13532Mi (208%)   | 4374Mi (67%)
cn-beijing.192.168.88.243  | 2035m (50%)   | 12200m (305%)  | 476m (11%)   | 2611Mi (40%)     | 13442Mi (207%)   | 5109Mi (78%)
cn-beijing.192.168.0.17    | 2475m (65%)   | 16000m (421%)  | 347m (9%)    | 3995Mi (61%)     | 25354Mi (391%)   | 4215Mi (65%)
cn-beijing.192.168.88.154  | 3055m (39%)   | 6600m (84%)    | 213m (2%)    | 1951Mi (13%)     | 7936Mi (55%)     | 5476Mi (38%)
```

支持显示pod数量

使用参数 --pod-count 可以显示节点的pod数量及可用数量,总可用数可不看,这块取不到节点规格的数量限制

```
% kubectl mytop --pod-count
NODE                       | CPU REQUESTS  | CPU LIMITS     | MEMORY REQUESTS  | MEMORY LIMITS    | POD COUNT
*                          | 17790m (56%)  | 92600m (294%)  | 20271Mi (37%)    | 130905Mi (240%)  | 138/213
cn-beijing.192.168.0.17    | 2475m (65%)   | 16000m (421%)  | 3995Mi (61%)     | 25354Mi (391%)   | 24/23
cn-beijing.192.168.0.246   | 2855m (71%)   | 11100m (277%)  | 3307Mi (51%)     | 13532Mi (208%)   | 16/23
cn-beijing.192.168.66.175  | 2755m (68%)   | 22600m (565%)  | 2822Mi (43%)     | 38243Mi (590%)   | 19/23
cn-beijing.192.168.88.154  | 3055m (39%)   | 6600m (84%)    | 1951Mi (13%)     | 7936Mi (55%)     | 12/48
cn-beijing.192.168.88.156  | 4615m (59%)   | 24100m (308%)  | 5586Mi (39%)     | 32399Mi (227%)   | 40/48
cn-beijing.192.168.88.243  | 2035m (50%)   | 12200m (305%)  | 2611Mi (40%)     | 13442Mi (207%)   | 27/48
```

支持使用label过滤想要的资源

mytop还支持pod,namespace,node的标签来过滤,如不同的namespace但是相同的pod label,可以汇聚展示,也可以指定node的节点池id作为label过滤,如下所示:

```
% kubectl mytop -p -u -l app=nginx
NODE                       | NAMESPACE  | POD                                      | CPU REQUESTS  | CPU LIMITS  | CPU UTIL     | MEMORY REQUESTS  | MEMORY LIMITS  | MEMORY UTIL
*                          | *          | *                                        | 500m (1%)     | 500m (1%)   | 3329m (9%)   | 0Mi (0%)         | 0Mi (0%)       | 32565Mi (47%)
                           |            |                                          |               |             |              |                  |                | 
cn-beijing.192.168.0.17    | *          | *                                        | 0Mi (0%)      | 0Mi (0%)    | 383m (10%)   | 0Mi (0%)         | 0Mi (0%)       | 4995Mi (77%)
                           |            |                                          |               |             |              |                  |                | 
cn-beijing.192.168.0.246   | *          | *                                        | 0Mi (0%)      | 0Mi (0%)    | 812m (20%)   | 0Mi (0%)         | 0Mi (0%)       | 4095Mi (63%)
                           |            |                                          |               |             |              |                  |                | 
cn-beijing.192.168.66.175  | *          | *                                        | 0Mi (0%)      | 0Mi (0%)    | 160m (4%)    | 0Mi (0%)         | 0Mi (0%)       | 3959Mi (61%)
                           |            |                                          |               |             |              |                  |                | 
cn-beijing.192.168.88.154  | *          | *                                        | 500m (6%)     | 500m (6%)   | 209m (2%)    | 0Mi (0%)         | 0Mi (0%)       | 5826Mi (40%)
cn-beijing.192.168.88.154  | default    | nginx-deployment-basic-7db987c47c-vz6bn  | 0Mi (0%)      | 0Mi (0%)    | 0Mi (0%)     | 0Mi (0%)         | 0Mi (0%)       | 0Mi (0%)
cn-beijing.192.168.88.154  | fanqinhe   | nginx-deployment-basic-7fbb7b675d-vtb6q  | 500m (6%)     | 500m (6%)   | 0Mi (0%)     | 0Mi (0%)         | 0Mi (0%)       | 0Mi (0%)
                           |            |                                          |               |             |              |                  |                | 
cn-beijing.192.168.88.156  | *          | *                                        | 0Mi (0%)      | 0Mi (0%)    | 1487m (19%)  | 0Mi (0%)         | 0Mi (0%)       | 8593Mi (60%)
                           |            |                                          |               |             |              |                  |                | 
cn-beijing.192.168.88.243  | *          | *                                        | 0Mi (0%)      | 0Mi (0%)    | 280m (7%)    | 0Mi (0%)         | 0Mi (0%)       | 5099Mi (78%)
                           |            |                                          |               |             |              |                  |                | 
cn-beijing.192.168.88.4    | *          | *                                        | 0Mi (0%)      | 0Mi (0%)    | 0Mi (0%)     | 0Mi (0%)         | 0Mi (0%)       | 0Mi (0%)
kubectl mytop --namespace default
kubectl mytop --namespace-labels app=ingress
kubectl mytop --node-labels kubernetes.io/role=node
%  kubectl mytop -p -u  --node-labels kubernetes.io/hostname=cn-beijing.192.168.88.154
NODE                       | NAMESPACE    | POD                                                     | CPU REQUESTS  | CPU LIMITS   | CPU UTIL   | MEMORY REQUESTS  | MEMORY LIMITS  | MEMORY UTIL
                           |              |                                                         |               |              |            |                  |                | 
cn-beijing.192.168.88.154  | *            | *                                                       | 3055m (39%)   | 6600m (84%)  | 226m (2%)  | 1951Mi (13%)     | 7936Mi (55%)   | 5600Mi (39%)
cn-beijing.192.168.88.154  | kube-system  | ack-node-problem-detector-daemonset-nwvxd               | 100m (1%)     | 1000m (12%)  | 59m (0%)   | 200Mi (1%)       | 1024Mi (7%)    | 41Mi (0%)
......
cn-beijing.192.168.88.154  | kube-system  | node-local-dns-nnbjc                                    | 25m (0%)      | 0Mi (0%)     | 1m (0%)    | 5Mi (0%)         | 1024Mi (7%)    | 22Mi (0%)
cn-beijing.192.168.88.154  | kube-system  | terway-eniip-m9877                                      | 350m (4%)     | 1100m (14%)  | 2m (0%)    | 200Mi (1%)       | 256Mi (1%)     | 169Mi (1%)
%  kubectl mytop -p -u --node-labels alibabacloud.com/nodepool-id=np288d2e8b77a3485b86461f64a60dc438
NODE                       | NAMESPACE            | POD                                                              | CPU REQUESTS  | CPU LIMITS     | CPU UTIL     | MEMORY REQUESTS  | MEMORY LIMITS         | MEMORY UTIL
*                          | *                    | *                                                                | 9945m (63%)   | 51200m (328%)  | 2381m (15%)  | 12888Mi (47%)    | 71285Mi (262%)        | 17649Mi (64%)
                           |                      |                                                                  |               |                |              |                  |                       | 
cn-beijing.192.168.0.17    | *                    | *                                                                | 2475m (65%)   | 16000m (421%)  | 393m (10%)   | 3995Mi (61%)     | 25354Mi (391%)        | 4981Mi (76%)
cn-beijing.192.168.0.17    | kube-system          | ack-node-local-dns-admission-controller-846bcf75dc-4tsmw         | 100m (2%)     | 1000m (26%)    | 1m (0%)      | 100Mi (1%)       | 1024Mi (15%)          | 20Mi (0%)
....
cn-beijing.192.168.0.17    | kube-system          | terway-eniip-nzbg4                                               | 350m (9%)     | 1100m (28%)    | 4m (0%)      | 200Mi (3%)       | 256Mi (3%)            | 175Mi (2%)
                           |                      |                                                                  |               |                |              |                  |                       | 
cn-beijing.192.168.0.246   | *                    | *                                                                | 2855m (71%)   | 11100m (277%)  | 561m (14%)   | 3307Mi (51%)     | 13532Mi (208%)        | 4091Mi (63%)
.....
cn-beijing.192.168.0.246   | kube-system          | terway-eniip-lm2sn                                               | 350m (8%)     | 1100m (27%)    | 3m (0%)      | 200Mi (3%)       | 256Mi (3%)            | 121Mi (1%)
                           |                      |                                                                  |               |                |              |                  |                       | 
cn-beijing.192.168.88.156  | *                    | *                                                                | 4615m (59%)   | 24100m (308%)  | 1429m (18%)  | 5586Mi (39%)     | 32399Mi (227%)        | 8578Mi (60%)
cn-beijing.192.168.88.156  | kube-system          | ack-node-local-dns-admission-controller-846bcf75dc-z7cfz         | 100m (1%)     | 1000m (12%)    | 1m (0%)      | 100Mi (0%)       | 1024Mi (7%)           | 16Mi (0%)
......
cn-beijing.192.168.88.156  | default              | yibei-echoserver-dc9f9b99c-c8z6r                                 | 250m (3%)     | 0Mi (0%)       | 1m (0%)      | 512Mi (3%)       | 0Mi (0%)              | 3Mi (0%)
```

支持的输出格式

默认情况下mytop以表格形式输出,也支持json或者yaml形式,参数参考:

```
kubectl mytop --pods --output json
kubectl mytop --pods --containers --util --output yaml
```

支持的参数

```
  -c, --containers                输出包含containers
      --context string            使用kubernetes config的上下文
  -h, --help                      kubectl-mytop 帮助参数
  -n, --namespace string          指定namespace
      --namespace-labels string   使用namespace的labels做过滤
      --node-labels string        使用node-labels做过滤
  -o, --output string             指定输出格式,默认table,支持以下三种
                                    (支持: [table json yaml])
                                    (默认: "table")
  -a, --available                 includes quantity available instead of percentage used
  -l, --pod-labels string         使用pod labels过滤
  -p, --pods                      展示pod的使用率
      --sort string               指定指标排序支持 (支持:
                                    [cpu.util cpu.request cpu.limit mem.util mem.request mem.limit name])
                                    (默认: "name")
  -u, --util                      展示使用率
      --pod-count                 展示pod数目及可用数(部分场景下不准)
```

依赖

所有指标来源依赖 metrics-server ,集群内需要部署metric-server ,以及使用的kubeconfig需要具备相关的权限

类似项目

以下项目有类似的功能,具体信息可自行打开观看

  • kube-resource-report: generates HTML/CSS report for resource requests and limits across multiple clusters.
  • kubetop: a CLI similar to top for Kubernetes, focused on resource utilization (not requests and limits).
  • kube-capacity) : a CLI similar to top for Kubernetes ,It attempts to combine the best parts of the output from kubectl top and kubectl describe into an easy to use CLI focused on cluster resources.

授权许可

Apache License 2.0


相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
目录
相关文章
|
2月前
|
Kubernetes 安全 容器
关于K8s,不错的开源工具
【10月更文挑战第12天】
|
8月前
|
Kubernetes 应用服务中间件 Docker
Kubernetes学习-集群搭建篇(二) 部署Node服务,启动JNI网络插件
Kubernetes学习-集群搭建篇(二) 部署Node服务,启动JNI网络插件
|
4月前
|
Ubuntu Linux pouch
Docker容器管理工具
文章介绍了Docker容器管理工具,以及早期使用的LXC容器管理工具,包括它们的安装、使用和相关技术特点。
93 10
Docker容器管理工具
|
8月前
|
存储 Kubernetes C++
【专栏】Kubernetes VS Docker Swarm了解两者特点,助力选取合适容器编排工具
【4月更文挑战第27天】对比Kubernetes和Docker Swarm:K8s在可扩展性和自动化方面出色,有强大社区支持;Swarm以简易用著称,适合初学者。选择取决于项目需求、团队技能和预期收益。高度复杂项目推荐Kubernetes,快速上手小项目则选Docker Swarm。了解两者特点,助力选取合适容器编排工具。
242 1
|
4月前
|
Kubernetes 容器 Perl
Kubernetes网络插件体系及flannel基础
文章主要介绍了Kubernetes网络插件体系,特别是flannel网络模型的工作原理、配置和测试方法。
135 3
|
4月前
|
Linux pouch 容器
CentOS7部署阿里巴巴开源的pouch容器管理工具实战
关于如何在CentOS 7.6操作系统上安装和使用阿里巴巴开源的Pouch容器管理工具的实战教程。
147 2
|
5月前
|
存储 Kubernetes Cloud Native
容器管理工具Containerd
容器管理工具Containerd
|
5月前
|
Prometheus Kubernetes 监控
揭秘Kubernetes的秘密武器库:十大工具让你的容器编排如虎添翼!探索这些神秘而强大的工具,它们将如何彻底改变你的Kubernetes体验?
【8月更文挑战第19天】在容器世界里,Kubernetes是部署与管理容器化应用的首选平台。为了增强其功能,本文精选了十大必备工具:Helm简化复杂应用部署;Prometheus监控系统与应用指标;Grafana提供数据可视化;Fluentd统一日志管理;Envoy实现服务间通信与控制;Calico确保网络连接安全;CoreDNS提升DNS服务性能;Velero保障数据安全与迁移;Argo Workflows执行复杂工作流;Istio强化服务网格功能。这些工具覆盖部署、监控、日志等多个方面,助力提升Kubernetes的效率与稳定性。
98 3
|
5月前
|
Kubernetes Cloud Native 开发者
OpenKruise:Kubernetes的超级插件,一键解锁容器运行时操作的超能力!
【8月更文挑战第8天】在云原生领域,Kubernetes虽已成为容器编排的标准,但仍有限制,比如批量操作不便和高级调度功能缺失。OpenKruise是一款增强工具,提供CloneSet、Advanced StatefulSet等功能,既保持Kubernetes API特性又增加了扩展性,使Pod管理更灵活。可通过Helm安装OpenKruise,并使用CloneSet轻松实现批量部署。这类增强工具让开发者能更高效地突破原生Kubernetes的限制,预计未来将更加受到欢迎。
85 8
|
5月前
|
Kubernetes 监控 Shell
在K8S中,我们公司用户反应pod连接数非常多,希望看一下这些连接都是什么信息?什么状态?怎么排查?容器里面没有集成bash环境、网络工具,怎么处理?
在K8S中,我们公司用户反应pod连接数非常多,希望看一下这些连接都是什么信息?什么状态?怎么排查?容器里面没有集成bash环境、网络工具,怎么处理?