Querying pods by multiple labels

Viewed 6442

I need to retrieve a list of pods by selecting their corresponding labels. When the pods have a simple label app=foo, k8s-app=bar, the selection is quite easy:

kubectl get po -l 'app in (foo), k8s-app in (bar)'

The complexity comes with labels that contain special characters, for example: app.kubernetes.io/name=foo So when I query only this label, I don't have a problem, but if I try to add this label to the existing query, it will end by returning no resources were found.

kubectl get po -l app.kubernetes.io/name=foo,app=bar
kubectl get po -l 'app.kubernetes.io/name in (foo), app in (bar)'

Any idea how can I join the two labels in a single query?

2 Answers

You can use below command for retrieving a list of pods by selecting their corresponding labels.

kubectl get pods --selector app=foo,k8s-app=bar
Related