How can i use kubectl labelselector with or contidion?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
kubectl label selectors do not provide a general-purpose OR operator. The important distinction is that Kubernetes supports OR-like matching for multiple values of the same key through set-based selectors, but it does not let you express arbitrary OR conditions across different keys in one plain selector string.
Comma-Separated Selectors Are Always AND
This is the first rule to remember:
That means:
Many people expect commas to act like a loose list of alternatives. In label selectors they do not. They add more requirements.
Use in (...) For OR On One Key
If the OR logic is "this key can have one of these values," use a set-based selector with in.
This is the Kubernetes-supported way to express:
You can still combine that with AND logic:
That means:
There Is No Single Selector For OR Across Different Keys
The tricky case is something like:
There is no single -l selector expression for that across different keys. The common workarounds are:
- run separate
kubectlqueries and merge the results - fetch a wider result set and filter with
jq - design labels so the OR condition becomes one key with multiple acceptable values
For example, separate queries:
Or JSON filtering:
Related reading
- How can I use local Docker images with Minikube?
- How can I use local Docker images with Minikube?
- How can kubernetes pods discover each other?
- How can one pipe stdin into a container in a pod in Kuberentes?
- How can I use tensorflow serving for multiple models
- How can I use tensorflow serving for multiple models
- How can the OR selector be used with labels in Kubernetes?
- How can we create service dependencies using kubernetes

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.