How to list the pods running in a particular zone?

11/15/2021

How to list the pods running in a particular zone? And suppose my cluster is configured into multiple zones, how to ensure pods are distributed into every zone?

-- Kraj
kubectl
kubernetes

2 Answers

11/16/2021

Topology key zone value is a label applied on nodes and so you can get the nodes with 'zone-value' and list pods of those nodes. Somethig like below,

kubectl get nodes -l zone:<zone value> -o json | jq '.items[].metadata.name' | xargs -I worker sh -c 'kubectl get pods -o wide | grep worker'

-- Aadhavan Rajasekar
Source: StackOverflow

12/16/2021
kubectl get nodes --show-labels|awk 'NR == 1 {next} {print $1,$6}'|awk -F "/" '{print $1,$NF}'|awk '{print $1,$NF}'|awk -F "=" '{print $1,$NF}'|awk '{print $1,"\t",$NF;}'
-- lansworld
Source: StackOverflow