<p>Is there any ability to filter by both namespace <strong>and</strong> pod's labels at the same time?</p>

<p>The example present in documentation at <a href="https://kubernetes.io/docs/user-guide/networkpolicies/#the-networkpolicy-resource" rel="noreferrer">https://kubernetes.io/docs/user-guide/networkpolicies/#the-networkpolicy-resource</a> </p>

<pre><code> - from:
 - namespaceSelector:
    matchLabels:
     project: myproject
 - podSelector:
    matchLabels:
     role: frontend
</code></pre>

<p>means that communication is allowed for pods with <code>role=frontend</code> <strong>or</strong> from <code>namespace myproject</code>.</p>

<p>Is there any way to change that "or" into an "and"?</p>

<p>Kubernetes 1.11 and above supports combining podSelector and namespaceSelector with a logical AND:</p>

<pre><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: database.postgres
  namespace: database
spec:
  podSelector:
    matchLabels:
      app: postgres
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          namespace: default
      podSelector:
        matchLabels:
          app: admin
  policyTypes:
  - Ingress
</code></pre>

<p>See more details in here: <a href="https://medium.com/@reuvenharrison/an-introduction-to-kubernetes-network-policies-for-security-people-ba92dd4c809d/#f416" rel="noreferrer">https://medium.com/@reuvenharrison/an-introduction-to-kubernetes-network-policies-for-security-people-ba92dd4c809d/#f416</a></p>
