<p>I do have a situation where, I do have 3 pods in the same namespace. Lets call them <code>aaa</code>, <code>bbb</code> and <code>ccc</code>.</p>
<p>Meanwhile NetworkPolicies are set in each of 2 of these to accept and forward traffic, let's say the <code>netpol</code> for <code>aaa</code> is <code>npa</code> and for <code>bbb</code> is <code>npb</code></p>
<p>My question is how can I allow <code>ccc</code> to allow traffic to ingress only from <code>aaa</code> and <code>bbb</code> by only configuring the pod and existing network policies</p>

Pasan Chamikara
<p>You can label the pods and add the network policy as shown below, it should allow traffic from aaa/bbb to ccc pod only</p>
<p>label existing pod:</p>
<pre><code>kubectl label pod aaa &quot;ns=aaa&quot;
kubectl label pod bbb &quot;ns=aaa&quot;
</code></pre>
<p>Network Policy: The below network policy will apply on pod ccc(app: ccc) and will only allow traffic from pods aaa and bbb this is what is required</p>
<p>note: assumed ccc is labelled as app: ccc</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: test-network-policy
  namespace: default
spec:
  podSelector:
    matchLabels:
      app: ccc
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          ns: aaa
   
</code></pre>
