Kubectl list pods sorted by Restart Count
In this tutorial, I will show you how to get the kubectl list pods sorted by Restart Count. Most of the time we want to get the pods in k8s but they are not sorted according to restart time. So, we sort the kubernetes pods according to restarts.
Read Also: Get Kubernetes events according to date using kubectl
Read Also: Kubectl cheat sheet
Get kubectl pods sorted by Restart Count
So let’s see how we can do that. First of all, let’s get pods.
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount' -n namespace
Pods in all namespaces
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount' -A
Please let me know if you like the tutorial.