kubectl get resources by label with OR operator

7/26/2019

I know we can do the following commands:

  • kubectl get pods -l app==<kafka> gets pods with kafka label
  • kubectl get pods -l app!=<kafka> gets pods without kafka label
  • kubectl get pods -l app=kafka,env=staging gets pods with both kafka and staging labels

But what about if I want to list all the pods which have either kafka or zookeeper label. Something like -l app==kafka||zookeeper.

Is this even possible with -l kubectl option...?

-- Ivan Aracki
kubectl
kubernetes

1 Answer

7/30/2019

Have you tried this?

kubectl get pods -l 'app in (kafka, zookeeper)'

See: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api

-- juancho85
Source: StackOverflow