How can i use kubectl labelselector with or contidion?

6/11/2021

I want to get pod with label

app=vovo component=db

When i get a pod with label app=vovo and component=db, i can get the result with below command.

kubectl get pod -l app=vovo,component=db

However, when i want to get the result

app=vovo or component=db

How can i get the result with one kubectl command?

-- sun
kubectl
kubernetes

1 Answer

6/11/2021

OR operations for label selection is not supported as per the documentation

Caution: For both equality-based and set-based conditions there is no logical OR (||) operator. Ensure your filter statements are structured accordingly

Here is a close hack you could do:

kubectl get pod -l app=volvo && kubectl get pod -l component=db --no-headers

This will run two kubectl queries for two different labels.

-- P....
Source: StackOverflow