Using kubectl
, I want to describe
one of the pods (can be a random one) filtered on a labelSelector. Currently, I perform it in two steps:
get
the pods,describe
it.$ kubectl get pods -l app=my-app,environment=production
$ kubectl describe pods my-pod-name-copied-from-the-results
Can I do that with a one-liner, and without copying the pod name every single time?
A one liner to get the first pod's decribe (if scaled to more than 1):
kubectl -n namespace describe po "$(kubectl -n namespace get po -l app.kubernetes.io/name=my-app --no-headers -o name|cut -d/ -f2|head -1)"
If you need a random one (as mentioned in the other answer's comments):
kubectl -n namespace describe po "$(kubectl -n namespace get po -l app.kubernetes.io/name=my-app --no-headers -o name|cut -d/ -f2|shuf -n1)"