Member-only story

Kubectl Tip #3

A weekly kubectl command you might find useful

Eric Fossas
2 min readJul 5, 2022
sort pod cpu and memory usage

Update

Not sure how I missed this one, but this functionality exists directly in kubectl with:

kubectl top po -A --sort-by=cpu

Thanks to emmanuel Gelati Mesa for pointing that out. I’ll leave the original tip here in case you anyone finds the tail or sort part out useful for other ideas.

The Command

The kubectl top command will show you the current cpu and memory usage of your pods. However, the pods are not sorted.

So this command will show you that data of every pod in your cluster and order all the pods by either their cpu or memory usage.

So it’s a quick and effective way of seeing which pods are currently using the most cpu or memory from top to bottom.

Why would you do this?

Sometimes you just need a quick snapshot of current resource usage in a cluster. It might help you quickly find a pod that’s not doing well with its resource usage.

It’s also useful for just getting an idea of the typical baseline usage of all your pods in the cluster so that you’re aware of which ones use more than others (at least at one moment in time).

Wrapping Up

Found the tip useful? if you did, please consider subscribing! I’ll be posting one tip every week for the rest of the year.

--

--

Responses (1)

Write a response