7

This is an extension to the question here - how can I get the list pods running on nodes with a certain label?

I am trying to find the pods in a specific zone (failure-domain.beta.kubernetes.io/zone)

vrtx54234
  • 2,196
  • 3
  • 30
  • 53

1 Answers1

5

You can get all nodes' name with the label you want using for command and list the pods within theses nodes:

Example:

for node in $(kubectl get nodes -l failure-domain.beta.kubernetes.io/zone=us-central1-c -ojsonpath='{.items[*].metadata.name}'); do kubectl get pods -A -owide --field-selector spec.nodeName=$node; done

The command will list all pods with label failure-domain.beta.kubernetes.io/zone=us-central1-c and then list the pods.

Mr.KoopaKiller
  • 3,665
  • 10
  • 21
  • Wasn't expecting something O(Nodes * Pods), but if this is the best possible then will have to take it.. – vrtx54234 Aug 26 '20 at 20:15