Search code examples
kuberneteskubectl

Retrieve pod description(kubectl describe) from the output of other expression


In kubectl, describe and get -o can be used to get the details of a resource, can we get a describe of only a list of selected pods (different labels), my case is to details of selected pod names for analysis. I'm using describe but unable to get details of specific pods, there are quite a few to do it manually.

If it was events/ specific labels, i could do the below but need more specific details of certain pods out of 100 of them

kubectl get describe po -l app2=test > desc.txt
Kubectl get events -n test|grep -E 'app2|app3|hello1' > events.txt

Tried the below it returns the events of all pods in the namespace (doesnt help), any simpler way or may be this cannot be done or write a script to loop through the o/p?

kubectl get po -n test |grep -E 'app2|app3|hello1' |awk '{print $1}'|k describe po  -n test > desc.txt

Thanks for the help!


Solution

  • Are you saying you can't use labels? Not sure I understand correctly but if you need to choose pods by name - this will work:

    kubectl get pod -oname | grep -E 'app2|app3|hello' | xargs kubectl describe