title: list the pods zone wise
body: <p>I am trying to list the pod's zone wise,</p>
  <p>for this, I am fetching the details of the node, where it has zones details along with Node Identifier, and whereas pods list has common Node Identifier, Now I want to club both results and want to print the pod's zone wise.
  <code>kubectl get nodes --label-columns failure-domain.beta.kubernetes.io/zone | awk '{print $1,$6}' | awk '{if (NR!=1) {print}}' | column -t &gt; Nodes</code></p>
  <p><code>kubectl get pods -n app -o wide | awk '{print $1, $7}' | column -t | awk '{if (NR!=1) {print}}' &gt; pods</code></p>
  <p>The desired output should be like</p>
  <pre><code>zone 1a
         pod 1   nodename status region
         pod 2   nodename status region
  
  zone 1b
         pod 1   nodename status region
         pod 2   nodename status region
  zone 1c
         pod 1   nodename status region
         pod 2   nodename status region
  zone 2a
         pod 1   nodename status region
         pod 2   nodename status region
  </code></pre>
  <p>script i tried,</p>
  <pre><code># bash scrip to print pods in each zone
  
  
  kubectl get nodes --label-columns failure-domain.beta.kubernetes.io/zone | awk '{print $1,$6}' | awk '{if (NR!=1) {print}}' | column -t &gt; A
  # get the pods list from app namespace
  kubectl get pods -n app -o wide | awk '{print $1, $7}' | column -t | awk '{if (NR!=1) {print}}' &gt; B
  # Compare file A and B and list the pods in each zone
  # &gt; AB
  cat A B 
  
  cat B | while read LINE;do
    matching_col=$(echo &quot;$LINE&quot;| awk '{print $2}');
    append_col=$(echo &quot;$LINE&quot;| awk '{print $1}');
    cat A | grep  $matching_col | head -1
    if [[ $? -eq 0 ]]; then
     line1=&quot;`cat A | grep $matching_col | head -1`    ${append_col}&quot;
     echo $line1 &gt;&gt; AB
    fi
  done
  # write the available zones list to C
  cat AB | awk '{print $3,$6}' | column -t | sort &gt; C
  # compare A and B and list the pods in each zone, comparing C and A
  for i in `cat C | awk '{print $1}'`; do
    echo &quot;pods in zone:&quot; $i
    kubectl get pods -n app -o wide | sed -n &quot;/$i/p&quot; 
  done
  
  # delete the files
  # rm AB
  # rm A
  # rm B
  # rm C
  </code></pre>
  <p>output from Node &gt; A</p>
  <pre><code>ip-192-5-1-199.eu-west-2.compute.internal  eu-west-2a
  ip-192-5-1-216.eu-west-2.compute.internal  eu-west-2a
  ip-192-5-2-212.eu-west-2.compute.internal  eu-west-2b
  ip-192-5-2-36.eu-west-2.compute.internal   eu-west-2b
  ip-192-5-3-157.eu-west-2.compute.internal
  ip-192-5-3-222.eu-west-2.compute.internal  eu-west-2c
  ip-192-5-3-45.eu-west-2.compute.internal   eu-west-2c
  </code></pre>
  <p>output from pods &gt; B</p>
  <pre><code>app-node-setup              ip-192-5-3-157.eu-west-2.compute.internal
  app-node-setup              ip-192-5-2-212.eu-west-2.compute.internal
  app-node-setup              ip-192-5-1-216.eu-west-2.compute.internal
  app-node-setup              ip-192-5-2-36.eu-west-2.compute.internal
  app-node-setup              ip-192-5-3-45.eu-west-2.compute.internal
  app-node-setup               ip-192-5-3-222.eu-west-2.compute.internal
  app-node-setup              ip-192-5-1-199.eu-west-2.compute.internal
  app-operator-5                     ip-192-5-3-45.eu-west-2.compute.internal
  telnet-1-accesspool         ip-192-5-1-199.eu-west-2.compute.internal
  telnet-1-accesspool          ip-192-5-3-222.eu-west-2.compute.internal
  telnet-1-manager            ip-192-5-2-212.eu-west-2.compute.internal
  storage-set-from-configmap-1-ss-5  ip-192-5-2-36.eu-west-2.compute.internal
  storage-set-from-configmap-1-ss-1  ip-192-5-3-157.eu-west-2.compute.internal
  storage-set-from-configmap-1-ss-2  &lt;none&gt;
  </code></pre>
  <p><code>Actual Output</code></p>
  <pre><code>kubectl get nodes --label-columns failure-domain.beta.kubernetes.io/zone
  
  NAME                                       STATUS   ROLES           AGE   VERSION            ZONE
  ip-192-0-1-199.eu-west-2.compute.internal   Ready    master,worker   23d   v1.20.11+e880017   eu-west-2a
  ip-192-0-1-216.eu-west-2.compute.internal   Ready    master,worker   23d   v1.20.11+e880017   eu-west-2a
  ip-192-0-2-212.eu-west-2.compute.internal   Ready    master,worker   23d   v1.20.11+e880017   eu-west-2b
  ip-192-0-2-36.eu-west-2.compute.internal    Ready    master,worker   23d   v1.20.11+e880017   eu-west-2b
  ip-192-0-3-157.eu-west-2.compute.internal   Ready    &lt;none&gt;          20d   v1.20.11+c343126
  ip-192-0-3-222.eu-west-2.compute.internal   Ready    master,worker   23d   v1.20.11+e880017   eu-west-2c
  ip-192-0-3-40.eu-west-2.compute.internal    Ready    master,worker   23d   v1.20.11+e880017   eu-west-2c
  
   kubectl get pods -n app -o wide
   NAME                                READY   STATUS    RESTARTS   AGE   IP               NODE                                       NOMINATED NODE   READINESS GATES
  app-node-setup-6qckk                1/1     Running   0          17d   169.24.206.214   ip-192-0-3-157.eu-west-2.compute.internal   &lt;none&gt;           &lt;none&gt;
  app-node-setup-ccwww                1/1     Running   0          17d   169.24.184.7     ip-192-0-2-212.eu-west-2.compute.internal   &lt;none&gt;           &lt;none&gt;
  app-node-setup-pn8vs                1/1     Running   0          17d   169.24.1925.242   ip-192-0-1-216.eu-west-2.compute.internal   &lt;none&gt;           &lt;none&gt;
  app-node-setup-pqm7s                1/1     Running   0          17d   169.24.56.85     ip-192-0-2-36.eu-west-2.compute.internal    &lt;none&gt;           &lt;none&gt;
  app-node-setup-qxd5c                1/1     Running   0          17d   169.24.246.139   ip-192-0-3-40.eu-west-2.compute.internal    &lt;none&gt;           &lt;none&gt;
  app-node-setup-rpm56                1/1     Running   0          17d   169.24.25.2192    ip-192-0-3-222.eu-west-2.compute.internal   &lt;none&gt;           &lt;none&gt;
  app-node-setup-wbf75                1/1     Running   0          17d   169.24.5.209     ip-192-0-1-199.eu-west-2.compute.internal   &lt;none&gt;           &lt;none&gt;
  app-operator-0                      1/1     Running   0          17d   169.24.246.137   ip-192-0-3-40.eu-west-2.compute.internal    &lt;none&gt;           &lt;none&gt;
  telnet-1-accesspool-1-ss-0           2/2     Running   3          17d   169.24.5.2192     ip-192-0-1-199.eu-west-2.compute.internal   &lt;none&gt;           &lt;none&gt;
  telnet-1-accesspool-1-ss-1           2/2     Running   2          17d   169.24.25.212    ip-192-0-3-222.eu-west-2.compute.internal   &lt;none&gt;           &lt;none&gt;
  telnet-1-manager-1-ss-0              4/4     Running   1          17d   169.24.184.8     ip-192-0-2-212.eu-west-2.compute.internal   &lt;none&gt;           &lt;none&gt;
  storage-set-from-configmap-1-ss-0   2/2     Running   3          17d   169.24.56.1923    ip-192-0-2-36.eu-west-2.compute.internal    &lt;none&gt;           &lt;none&gt;
  storage-set-from-configmap-1-ss-1   2/2     Running   6          17d   169.24.206.218   ip-192-0-3-157.eu-west-2.compute.internal   &lt;none&gt;           &lt;none&gt;
  storage-set-from-configmap-1-ss-2   0/2     Pending   0          17d   &lt;none&gt;           &lt;none&gt;                                     &lt;none&gt;           &lt;none&gt;
  </code></pre>