首页 > 解决方案 > List `kubectl top pods` filtered by node

问题描述

Is there a way to get top pods filtered by node?

Use case: I have a node which is reported to use 103% of the cpu and I want to validate which pods are causing it.

标签: kubernetes

解决方案


我认为没有直接的方法可以使用kubectl top pods命令来执行此操作,因为过滤的唯一选项是仅适用于 pod 的标签/选择器。

对于您的用例,您可以使用以下命令:

kubectl get pods -o wide | grep <node> | awk {'print $1'} | xargs -n1 command kubectl top pods --no-headers

  • kubectl get pods -o wide: 显示 pod 及其关联的节点信息
  • grep <node>:让您过滤位于特定节点上的 pod
  • awk {'print $1'}:打印第一列(豆荚的名称)
  • xargs -n1 command kubectl top pods --no-headers: 为每个不带 headers (NAME, CPU, MEMORY) 的 pod 执行 top 命令

此外,您可以使用以下命令检查为一个特定节点中的每个 pod 设置的限制kubectl describe node <node>


推荐阅读