<p>Is there a way to combine <code>kubectl top pod</code> and <code>kubectl top nodes</code>?</p>
<p>Basically I want to know pods sorted by cpu/memory usage <strong>BY</strong> node.</p>
<p>I can only get pods sorted by memory/cpu for whole cluster with <code>kubectl top pod</code> or directly memory/cpu usage per whole node with <code>kubectl top nodes</code>.</p>
<p>I have been checking the documentation but couldnt find the exact command.</p>

<p>There is no built-in solution to achieve your expectations. <code>kubectl top pod</code> and <code>kubectl top node</code> are different commands and cannot be mixed each other. It is possible to <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#interacting-with-running-pods" rel="nofollow noreferrer">sort results</a> from <code>kubectl top pod</code> command only by <code>cpu</code> or <code>memory</code>:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl top pod POD_NAME --sort-by=cpu              # Show metrics for a given pod and sort it by 'cpu' or 'memory'
</code></pre>
<p>If you want to &quot;combine&quot; <code>kubectl top pod</code> and <code>kubectl top node</code> you need to write custom solution. For example script in Bash based on <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/" rel="nofollow noreferrer">this commands</a>.</p>
