Kubernetes - 使用 kubectl 显示当前 pods 与容量

Kubernetes - display current pods vs. capacity with kubectl

Kubernetes 仪表板能够显示每个节点 "current running pods / pods capacity"。但是,当我尝试使用 kubectl 获取相同的信息时,我必须 运行 两个命令:

kubectl describe node | grep -E (^Name:|^Non-terminated)

其中列出了 "current running pod on node" 和

kubectl get nodes -o=custom-columns=NAME:.metadata.name,CAPACITY:.status.capacity.pods

显示节点的容量

有谁知道我如何仅使用 一个命令 获得类似于下面的输出?

NAME     CURRENT   CAPACITY
node_1   7         15
node_2   8         15
node_3   15        15

提前致谢!

没有一个命令

可以编写脚本来组合这两个命令。

请注意,使用 pods 数量等基于整数的指标可能会产生误导,因为 pods 会因 space 和消耗的 cpu 而异。在达到节点 Pod 计数容量之前,您可能会用完 CPU 和内存。

您可以使用命令查看可用资源:kubectl top nodes

Node capacity

The capacity of the node (number of cpus and amount of memory) is part of the node object. Normally, nodes register themselves and report their capacity when creating the node object. If you are doing manual node administration, then you need to set node capacity when adding a node.

The Kubernetes scheduler ensures that there are enough resources for all the pods on a node. It checks that the sum of the requests of containers on the node is no greater than the node capacity. It includes all containers started by the kubelet, but not containers started directly by the container runtime nor any process running outside of the containers.

P.S.

在 Debian 上,第一个命令必须稍微修改才能工作:

kubectl describe node | grep -E "(^Name:|^Non-terminated)"