43 个版本
0.19.2 | 2024年4月23日 |
---|---|
0.18.1 | 2023年11月25日 |
0.18.0 | 2023年10月29日 |
0.16.3 | 2023年4月2日 |
0.6.0 | 2019年11月28日 |
#289 在 开发工具
183 每月下载量
在 kdash 中使用
68KB
1.5K SLoC
kubectl-view-allocations
kubectl
插件列出节点和运行中的 Pod 清单中定义的资源(CPU、内存、GPU...)的分配。它不列出使用情况,如 kubectl top
。它可以按命名空间、节点、Pod 分组结果,并通过资源名称进行过滤。
显示的列
Requested
: Pod 清单中容器请求的资源量。它是按 Pod、命名空间、运行容器的节点分组求和。包括组内请求的资源占可分配资源的百分比。Limit
: Pod 清单中容器最大(限制)请求的资源量。它是按 Pod、命名空间、运行容器的节点分组求和。包括组内最大/限制资源占可分配资源的百分比。Allocatable
: 节点上定义(或检测到的)可分配资源。Free
:Allocatable - max (Limit, Requested)
Utilization
: 由 Metrics API 报告的资源(CPU 和内存)使用量。默认禁用,metrics-server 是可选的,应配置在集群中。
安装
通过下载二进制文件
从 GitHub 发布版 下载或使用脚本
curl https://raw.githubusercontent.com/davidB/kubectl-view-allocations/master/scripts/getLatest.sh | bash
通过 krew(kubectl 插件管理器)
kubectl krew install view-allocations
通过 cargo
cargo install kubectl-view-allocations
作为 Cargo.toml 中的库
如果您想将插件的一些函数或结构嵌入到其他 Rust 代码中
[dependencies]
kubectl-view-allocations = { version = "0.14", default-features = false }
[features]
default = ["k8s-openapi/v1_20"]
用法
显示帮助
> kubectl-view-allocations -h
kubectl plugin to list allocations (cpu, memory, gpu,... X utilization, requested, limit, allocatable,...)
Usage: kubectl-view-allocations [OPTIONS]
Options:
--context <CONTEXT> The name of the kubeconfig context to use
-n, --namespace <NAMESPACE> Show only pods from this namespace
-u, --utilization Force to retrieve utilization (for cpu and memory), require to have metrics-server https://github.com/kubernetes-sigs/metrics-server
-z, --show-zero Show lines with zero requested and zero limit and zero allocatable
--precheck pre-check access and refersh token on kubeconfig by running `kubectl cluster-info`
--accept-invalid-certs accept invalid certificats (dangerous)
-r, --resource-name <RESOURCE_NAME> Filter resources shown by name(s), by default all resources are listed
-g, --group-by <GROUP_BY> Group information hierarchically (default: -g resource -g node -g pod) [possible values: resource, node, pod, namespace]
-o, --output <OUTPUT> Output format [default: table] [possible values: table, csv]
-h, --help Print help
-V, --version Print version
https://github.com/davidB/kubectl-view-allocations
显示 GPU 分配
> kubectl-view-allocations -r gpu
Resource Requested Limit Allocatable Free
nvidia.com/gpu (71%) 10.0 (71%) 10.0 14.0 4.0
├─ node-gpu1 (0%) __ (0%) __ 2.0 2.0
├─ node-gpu2 (0%) __ (0%) __ 2.0 2.0
├─ node-gpu3 (100%) 2.0 (100%) 2.0 2.0 __
│ └─ fah-gpu-cpu-d29sc 2.0 2.0 __ __
├─ node-gpu4 (100%) 2.0 (100%) 2.0 2.0 __
│ └─ fah-gpu-cpu-hkg59 2.0 2.0 __ __
├─ node-gpu5 (100%) 2.0 (100%) 2.0 2.0 __
│ └─ fah-gpu-cpu-nw9fc 2.0 2.0 __ __
├─ node-gpu6 (100%) 2.0 (100%) 2.0 2.0 __
│ └─ fah-gpu-cpu-gtwsf 2.0 2.0 __ __
└─ node-gpu7 (100%) 2.0 (100%) 2.0 2.0 __
└─ fah-gpu-cpu-x7zfb 2.0 2.0 __ __
仅概述
> kubectl-view-allocations -g resource
Resource Requested Limit Allocatable Free
cpu (21%) 56.7 (65%) 176.1 272.0 95.9
ephemeral-storage (0%) __ (0%) __ 38.4T 38.4T
memory (8%) 52.7Gi (15%) 101.3Gi 675.6Gi 574.3Gi
nvidia.com/gpu (71%) 10.0 (71%) 10.0 14.0 4.0
pods (9%) 147.0 (9%) 147.0 1.6k 1.5k
显示利用情况
- 利用率信息从metrics-server(应在您的集群上设置)中检索。
- 仅报告CPU和内存利用率。
> kubectl-view-allocations -u
Resource Utilization Requested Limit Allocatable Free
cpu (0%) 9.0m (10%) 200.0m __ 2.0 1.8
└─ lima-rancher-desktop (0%) 9.0m (10%) 200.0m __ 2.0 1.8
├─ coredns-96cc4f57d-57cj9 1.0m 100.0m __ __ __
├─ local-path-provisioner-84bb864455-czzcg 1.0m __ __ __ __
├─ metrics-server-ff9dbcb6c-kb7x9 4.0m 100.0m __ __ __
├─ svclb-traefik-ggd2q 2.0m __ __ __ __
└─ traefik-55fdc6d984-sqp57 1.0m __ __ __ __
ephemeral-storage __ __ __ 99.8G __
└─ lima-rancher-desktop __ __ __ 99.8G __
memory (1%) 51.0Mi (2%) 140.0Mi (3%) 170.0Mi 5.8Gi 5.6Gi
└─ lima-rancher-desktop (1%) 51.0Mi (2%) 140.0Mi (3%) 170.0Mi 5.8Gi 5.6Gi
├─ coredns-96cc4f57d-57cj9 11.5Mi 70.0Mi 170.0Mi __ __
├─ local-path-provisioner-84bb864455-czzcg 6.2Mi __ __ __ __
├─ metrics-server-ff9dbcb6c-kb7x9 14.9Mi 70.0Mi __ __ __
├─ svclb-traefik-ggd2q 548.0Ki __ __ __ __
└─ traefik-55fdc6d984-sqp57 17.9Mi __ __ __ __
pods __ (5%) 5.0 (5%) 5.0 110.0 105.0
└─ lima-rancher-desktop __ (5%) 5.0 (5%) 5.0 110.0 105.0
按命名空间分组。
> kubectl-view-allocations -g namespace
Resource Requested Limit Allocatable Free
cpu (10%) 200.0m __ 2.0 1.8
└─ kube-system 200.0m __ __ __
ephemeral-storage __ __ 99.8G __
memory (2%) 140.0Mi (3%) 170.0Mi 5.8Gi 5.6Gi
└─ kube-system 140.0Mi 170.0Mi __ __
pods (5%) 5.0 (5%) 5.0 110.0 105.0
└─ kube-system 5.0 5.0 __ __
以CSV格式显示。
在这种情况下,值以浮点数形式展开(保留2位小数)。
kubectl-view-allocations -o csv
Date,Kind,resource,node,pod,Requested,%Requested,Limit,%Limit,Allocatable,Free
2020-08-19T19:12:48.326605746+00:00,resource,cpu,,,59.94,22%,106.10,39%,272.00,165.90
2020-08-19T19:12:48.326605746+00:00,node,cpu,node-gpu1,,2.31,19%,4.47,37%,12.00,7.53
2020-08-19T19:12:48.326605746+00:00,pod,cpu,node-gpu1,yyy-b8bd56fbd-5x8vq,1.00,,2.00,,,
2020-08-19T19:12:48.326605746+00:00,pod,cpu,node-gpu1,kube-flannel-ds-amd64-7dz9z,0.10,,0.10,,,
2020-08-19T19:12:48.326605746+00:00,pod,cpu,node-gpu1,node-exporter-gpu-b4w7s,0.11,,0.22,,,
2020-08-19T19:12:48.326605746+00:00,pod,cpu,node-gpu1,xxx-backend-7d84544458-46qnh,1.00,,2.00,,,
2020-08-19T19:12:48.326605746+00:00,pod,cpu,node-gpu1,weave-scope-agent-bbdnz,0.10,,0.15,,,
2020-08-19T19:12:48.326605746+00:00,node,cpu,node-gpu2,,0.31,1%,0.47,2%,24.00,23.53
2020-08-19T19:12:48.326605746+00:00,pod,cpu,node-gpu2,kube-flannel-ds-amd64-b5b4v,0.10,,0.10,,,
2020-08-19T19:12:48.326605746+00:00,pod,cpu,node-gpu2,node-exporter-gpu-796jz,0.11,,0.22,,,
2020-08-19T19:12:48.326605746+00:00,pod,cpu,node-gpu2,weave-scope-agent-8rhnd,0.10,,0.15,,,
2020-08-19T19:12:48.326605746+00:00,node,cpu,node-gpu3,,3.41,11%,6.67,21%,32.00,25.33
...
它可以与“分组”选项结合使用。
kubectl-view-allocations -g resource -o csv
Date,Kind,resource,Requested,%Requested,Limit,%Limit,Allocatable,Free
2020-08-19T19:11:49.630864028+00:00,resource,cpu,59.94,22%,106.10,39%,272.00,165.90
2020-08-19T19:11:49.630864028+00:00,resource,ephemeral-storage,0.00,0%,0.00,0%,34462898618662.00,34462898618662.00
2020-08-19T19:11:49.630864028+00:00,resource,hugepages-1Gi,0.00,,0.00,,,
2020-08-19T19:11:49.630864028+00:00,resource,hugepages-2Mi,0.00,,0.00,,,
2020-08-19T19:11:49.630864028+00:00,resource,memory,69063409664.00,10%,224684670976.00,31%,722318667776.00,497633996800.00
2020-08-19T19:11:49.630864028+00:00,resource,nvidia.com/gpu,3.00,27%,3.00,27%,11.00,8.00
2020-08-19T19:11:49.630864028+00:00,resource,pods,0.00,0%,0.00,0%,1540.00,1540.00
替代方案及类似产品
- 查看讨论需要简单的kubectl命令来查看集群资源使用情况 · Issue #17512 · kubernetes/kubernetes
- 仅针对CPU和内存
- 仅针对CPU和内存利用率
kubectl top pods
- LeastAuthority/kubetop:Kubernetes的类似top(1)的工具。
依赖项
~82MB
~1.5M SLoC