<p>How do I get top three most CPU utilized pod in a Kubernetes cluster?</p>

<pre><code>kubectl top po --all-namespaces 
</code></pre>

<p>Above command gives me CPU and memory utilization for all the pods across all namespaces. How to restrict it to only top three most CPU utilized pods?</p>

<p>Also, I've tried to sort by CPU, but seems like sorting is not working.</p>

<pre><code>kubectl top po --all-namespaces --sort-by="cpu"
</code></pre>

<p>Output:</p>

<pre><code>NAMESPACE     NAME                             CPU(cores)   MEMORY(bytes)
kube-system   weave-net-ksfp4                  1m           51Mi
kube-system   kube-controller-manager-master   10m          50Mi
kube-system   coredns-5644d7b6d9-rzd64         2m           6Mi
kube-system   weave-net-h4xlg                  1m           77Mi
kube-system   kube-proxy-lk9xv                 1m           19Mi
kube-system   coredns-5644d7b6d9-v2v4m         3m           6Mi
kube-system   kube-scheduler-master            2m           21Mi
kube-system   kube-apiserver-master            26m          228Mi
kube-system   kube-proxy-lrzjh                 1m           9Mi
kube-system   etcd-master                      12m          38Mi
kube-system   metrics-server-d58c94f4d-gkmql   1m           14Mi
</code></pre>

Naseem Khan
<p>The sorting should be fixed in the next release - <a href="https://github.com/kubernetes/kubernetes/issues/81270" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/81270</a> </p>

<p>In the mean time you <a href="https://github.com/kubernetes/kubernetes/issues/81270#issuecomment-578144523" rel="nofollow noreferrer">can use this</a></p>

<pre><code>kubectl top pod --all-namespaces --no-headers \
 | sort --key 3 --numeric \
 | tail -3
</code></pre>
