<p>kubernetes V19</p>
<p>Create a new NetworkPolicy named allow-port-from-namespace that allows Pods in the existing namespace internal to connect to port 80 of other Pods in the same namespace.</p>
<p>Ensure that the new NetworkPolicy:</p>
<p>does not allow access to Pods not listening on port 80
does not allow access from Pods not in namespace internal</p>
<p>i need to know if i can do it without adding a labels to namspace and pod or not ?</p>

<ol>
<li>You need to label the namespace first</li>
</ol>
<p>For e.g <strong>kubectl label ns namespace-name env: testing</strong></p>
<p>2.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-port-from-namespace
  namespace: staging
spec:
  podSelector: {} 
  policyTypes:
  - Ingress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          env: staging
    ports:
    - protocol: TCP
      port: 80
</code></pre>
