NetworkPolicy with OR option in namespaceSelector

8/5/2019

How can I write the following in namespaceSelector:

key=val OR key1=val1?

the following example is for AND, how can i write something for the OR option?

matchExpressions:
            - {key: app, operator: In, values: [application]}
            - {key: app1, operator: In, values: [application1]}

i find option to do OR between values (see below in the image) but not between keys.

{key: app, operator: In, values: [application, app2, app3]}
-- inza
kubernetes

1 Answer

8/5/2019

For the matchExpressions the definition is that all expressions must match (AND). In official Kubernetes documentation you can read:

All of the requirements, from both matchLabels and matchExpressions are ANDed together – they must all be satisfied in order to match.

You could add multiple from terms to your network policy, for them only one needs to match (OR). More on behavior of to and from selectors.

-- Thomas
Source: StackOverflow