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

标签 kubernetes kubectl

Kubernetes 仪表板能够显示每个节点的“当前运行的 pod/pod 容量”。但是当我尝试使用 kubectl 获取相同的信息时,我必须运行两个命令:

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

其中列出了“节点上当前正在运行的 pod”,以及

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

提前致谢!

最佳答案

对此没有一个命令

可以通过组合这两个命令来编写脚本来执行此操作。

请注意,使用基于整数的指标(如 Pod 数量)可能会产生误导,因为 Pod 消耗的空间和 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.

附言

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

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

关于Kubernetes - 使用 kubectl 显示当前 pod 与容量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58201823/

相关文章:

mongodb - 扩展架构时的Cors和数据库uri问题

sorting - Kubernetes:按年龄升序显示 Pod

docker - 在 Kubernetes 内运行的 Docker Private Registry 的多用户身份验证

ssh - 在 kubernetes 中创建 ssh secrets key 文件

kubernetes - kubectl中的port选项有什么用

kubernetes api 服务器在普罗米修斯(kube-state-metrics)中显示 - -"forbidden: User\"系统 :anonymous\"cannot get path\"/metrics\"",

azure - 用于在 Azure AKS 中提取每个命名空间数据的托管解决方案

logging - kubernetes:kubectl 没有检索到日志

kubernetes - prometheus 动态metrics_path

Kubernetes - 批量删除所有作业