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?
Currently, Kubernetes does not support OR in label selectors. You can only OR different values of the same label (like kubectl get pods -l 'app in (foo,bar)').
See also How can the OR selector be used with labels in Kubernetes?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With