<p>I would like to save node name which consuming highest CPU (in the current namespace) into the file.</p>
<p><code>kubectl top node</code> provide you all nodes information, need to pick the top one from the list.</p>

sachin
<p>Ideal command to get the sorted list is <code>kubectl top node --no-headers --sort-by='cpu' | head -1 &gt; somefilename.txt</code>, but the result will be inconsistent due to open issue <a href="https://github.com/kubernetes/kubernetes/issues/81270" rel="nofollow noreferrer">kubectl top issue</a></p>
<p>As a workaround you can try this command if you are running in any linux/mac OS:</p>
<p><code>kubectl top node --no-headers | sort -k3 -n | tail -1 &gt; somefilename.txt</code></p>
<p>This issue has been resolved in kubectl 1.18.</p>
