Answers: <p>The best I have found so far for part 2 is to use the JSON output of <code>get pods</code>:</p>
  
  <pre><code>kubectl get pods -o json | jq '.items[] | select(.metadata.labels."app.kubernetes.io/name") | { name: .metadata.labels."app.kubernetes.io/name", version: .metadata.labels."app.kubernetes.io/version" }'
  </code></pre>
  
  <p>produces</p>
  
  <pre><code>{
    "name": "db",
    "version": "0.0.1"
  }
  {
    "name": "app",
    "version": "0.0.1"
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-06-16T23:56:04.907Z
Answers: That's definitely a nicer result than I'm currently producing. It does require that anyone using the command have `jq` installed which I guess is a reasonable requirement. Conversely what I'm currently doing requires that everyone have `grep` installed.
Answers: Guy
Answers: CC BY-SA 4.0
Answers: 2020-06-19T19:05:30.007Z
Answers: I'd suggest using `-o jsonpath` or `-o custom-columns` to avoid external dependencies.
Answers: LLlAMnYP
Answers: CC BY-SA 4.0
Answers: 2020-06-16T23:06:19.373Z
Answers: 2020-06-16T23:06:19.373Z
Answers: Chris Crewdson
Answers: <p>For listing versions of each container in each pod I found that the <a href="https://github.com/chenjiandongx/kubectl-images" rel="nofollow noreferrer">kubectl-images</a> plugin is quite useful.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-06-18T16:28:32.053Z
Answers: 2020-06-18T16:28:32.053Z
Answers: Mikhail Advani
Body: <p>I have multiple clusters that I want to query and in each cluster I want to find and list the versions of the pods running in there.</p>
  
  <p>I've written a shell script that sets the namespace and then changes context to each cluster and then runs <code>kubectl describe pods | grep "/version=" -B1</code> in each cluster.</p>
  
  <p>This seems to be a very hacky and clumsy approach to this problem. Is there a succinct command in the Kubernetes realm that I can issue that will take a list of clusters and return the name/version of each pod?</p>
  
  <p>I feel that there are 2 problems described here and help with either or both would be appreciated:</p>
  
  <ol>
  <li>How do I issue commands like <code>kubectl describe pods</code> to multiple clusters at the same time and aggregate those results?</li>
  <li>What is best way to list names with versions of each pod in a cluster?</li>
  </ol>
  
  <p>Update: I built an assumption into the questions that the answer would be a scripted <code>kubectl</code> command but it does not need to be. The objective is to find all the name/version combos of all pods running in listed clusters.</p>
  
Tags: <kubernetes><kubectl>
Title: How do I list pod name/version across multiple clusters in Kubernetes
UserDisplayName: Guy
ThreadText: # How do I list pod name/version across multiple clusters in Kubernetes
  
  (Asked by: username_0 on 2020-06-16)
  
  I have multiple clusters that I want to query and in each cluster I want to find and list the versions of the pods running in there.
  
  I've written a shell script that sets the namespace and then changes context to each cluster and then runs `kubectl describe pods | grep "/version=" -B1` in each cluster.
  
  This seems to be a very hacky and clumsy approach to this problem. Is there a succinct command in the Kubernetes realm that I can issue that will take a list of clusters and return the name/version of each pod?
  
  I feel that there are 2 problems described here and help with either or both would be appreciated:
  
  1. How do I issue commands like `kubectl describe pods` to multiple clusters at the same time and aggregate those results?
  2. What is best way to list names with versions of each pod in a cluster?
  
  Update: I built an assumption into the questions that the answer would be a scripted `kubectl` command but it does not need to be. The objective is to find all the name/version combos of all pods running in listed clusters.
  
  **Tags:** kubernetes, kubectl
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-06-16. Score: 2
  
  The best I have found so far for part 2 is to use the JSON output of `get pods`:
  
  ```
  kubectl get pods -o json | jq '.items[] | select(.metadata.labels."app.kubernetes.io/name") | { name: .metadata.labels."app.kubernetes.io/name", version: .metadata.labels."app.kubernetes.io/version" }'
  
  ```
  
  produces
  
  ```
  {
    "name": "db",
    "version": "0.0.1"
  }
  {
    "name": "app",
    "version": "0.0.1"
  }
  
  ```
  
  > **Comments:**
  > **username_0**: That's definitely a nicer result than I'm currently producing. It does require that anyone using the command have `jq` installed which I guess is a reasonable requirement. Conversely what I'm currently doing requires that everyone have `grep` installed.  
  > **username_2**: I'd suggest using `-o jsonpath` or `-o custom-columns` to avoid external dependencies.  
  
  ---
  
  ### Answer by username_3 on 2020-06-18. Score: 0
  
  For listing versions of each container in each pod I found that the [kubectl-images](https://github.com/chenjiandongx/kubectl-images) plugin is quite useful.
  
  
  ---
  
  