How to sort pods with respect to their IPs

4/15/2019

How to sort the pods with respect to it's IP or it's Node IP.

I tried this command and I have around 20 pods running on my 3 node cluster.

kubectl get pods --all-namespaces --sort-by={'.spec.ip'}

error: ip is not found

this is the error I am getting

-- MR.i
kubernetes

2 Answers

4/21/2020

I have created a kubesort to simplify sorting. It may help you.

-- AATHITH RAJENDRAN
Source: StackOverflow

4/15/2019

You're using the wrong command to sort. The correct command will be:

kubectl get pods --all-namespaces --sort-by={.status.podIP}

This will sort your pods according to the podIP.

-- Prafull Ladha
Source: StackOverflow