简体   繁体   English

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

[英]Kubernetes - display current pods vs. capacity with kubectl

Kubernetes dashboard is able to show "current running pods / pods capacity" per node. Kubernetes 仪表板能够显示每个节点的“当前运行的 Pod/Pod 容量”。 But when I try to get the same info with kubectl I have to run two commands:但是当我尝试使用kubectl获取相同的信息时,我必须运行两个命令:

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

which lists "current running pod on node", and其中列出了“节点上当前正在运行的 pod”,以及

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

which shows the node's capacity显示节点的容量

Does anyone know how I can get the output similar to below using one command only?有谁知道我如何仅使用一个命令获得类似于下面的 output ?

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

Thanks in advance!提前致谢!

There is no one command for this.没有一个命令可以做到这一点。

It is possible to write script to do that with combining those two commands.可以通过结合这两个命令来编写脚本来做到这一点。

Note that using integer based metrics like number of pods can be very misleading as pods can vary in how much space and cpus they consume.请注意,使用基于 integer 的指标(例如 pod 数量)可能会产生很大的误导性,因为 pod 消耗的空间和 CPU 量可能会有所不同。 You might use up cpus and memory before you reach node pod count capacity.在达到节点 pod 计数容量之前,您可能会用完 cpus 和 memory。

You can check available resources with command: kubectl top nodes您可以使用以下命令检查可用资源: kubectl top nodes

Node capacity节点容量

The capacity of the node (number of cpus and amount of memory) is part of the node object.节点的容量(cpu 数量和内存量)是节点 object 的一部分。 Normally, nodes register themselves and report their capacity when creating the node object.通常,节点在创建节点 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. Kubernetes 调度程序确保有足够的资源用于节点上的所有 Pod。 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.它包括由 kubelet 启动的所有容器,但不包括由 容器运行时直接启动的容器,也不包括在容器之外运行的任何进程。

PS附言

On Debian the first command had to be slightly modified to work:在 Debian 上,必须稍微修改第一个命令才能工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM