1

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.

2 Answers 2

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"
}
2
  • 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.
    – Guy
    Commented Jun 16, 2020 at 23:56
  • 2
    I'd suggest using -o jsonpath or -o custom-columns to avoid external dependencies.
    – LLlAMnYP
    Commented Jun 19, 2020 at 19:05
0

For listing versions of each container in each pod I found that the kubectl-images plugin is quite useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.