<p>I have two types of pods A and B</p>
<p>Pod Type <strong>A</strong></p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: A
  labels:
    environment: production
spec:
...
</code></pre>
<p>Pod Type <strong>B</strong></p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: B
  labels:
    environment: production
spec:
...
</code></pre>
<p>And a NetworkPolicy (still don't know the proper way to use podselection)</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
spec:
  podSelector: {&quot;A&quot;, &quot;B&quot;}
  policyTypes:
  - Ingress
  - Egress
</code></pre>
<p><strong>Question :</strong> How do I define a single <code>NetworkPolicy</code> to limit traffic to only A &amp; B pods (both ingress &amp; egress) using a '<code>NetworkPolicy</code>' in Kubernetes</p>
<p><em>References used : <a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/network-policies/</a></em></p>

JumbledCode
<p>pod selectors do not have <code>or</code> condition on <code>labels</code>. The solution will be to create a common label in both pods - <code>a</code> and <code>b</code> and use pod selector on that common label.</p>
<p>In your question, you should use <code>environment: production</code> as a label to select correct pods. Pod selector works on <code>labels</code> and not the <code>name</code> of the pod.</p>
