<p>I am trying to create a network policy for the following conditions but does not seem to work. What am I doing wrong?  Any help is much appreciated</p>
<ul>
<li>create a network policy namespace project-e</li>
<li>the policy should allow all pods in namespace <strong>project-app</strong> to connect to <strong>port 8000</strong> of Pods in namespace <strong>project-e</strong></li>
<li>the policy should not allow access to pods that don't listen on port 8000</li>
<li>the policy does not allow access from pods that are not in namespace project-app</li>
</ul>
<pre><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: test-network-policy
  namespace: project-e
spec:
  podSelector:
    matchLabels: {}
  policyTypes:
  - Ingress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          name: project-app
    - podSelector:
        matchLabels: {}
    ports:
    - protocol: TCP
      port: 8000
</code></pre>

<ul>
<li><p>since you want to allow all the pods from namespace which has a label &quot;name:
project-app&quot; to namespace <code> project-e</code>.</p>
</li>
<li><p>You can remove the the <code> matchLables:{}</code> in <code>podSelector</code> as following :</p>
</li>
</ul>
<pre><code>kind: NetworkPolicy
metadata:
  name: test-network-policy
  namespace: project-e
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          name: project-app
    - podSelector: {}
    ports:
    - protocol: TCP
      port: 8000
</code></pre>
<ul>
<li>Make sure namespace <code>project-app</code> has a label <code>name: project-app</code>. Otherwise change it to appropriate label in above manifest.</li>
</ul>
