<p>I spent all morning but unable to make progress on getting network policies to work as expected. Please find below the services I have running in my cluster.</p>
<p>All ingress and egress patterns per network policy are working as expected except for curl calls from pod/mydeploy2-784fbfd764-mfslq  to pod/mydeploy-5865fb49b4-ks7sx.</p>
<pre><code>NAME                             READY   STATUS    RESTARTS   AGE    LABELS
pod/mydeploy-5865fb49b4-ks7sx    1/1     Running   0          108m   app=mydeploy,pod-template-hash=5865fb49b4
pod/mydeploy2-784fbfd764-mfslq   1/1     Running   0          103m   app=mydeploy2,pod-template-hash=784fbfd764
pod/nginx-77b4fdf86c-w55np       1/1     Running   0          138m   app=nginx,pod-template-hash=77b4fdf86c
pod/nginx2-6f69878b4f-jvgn2      1/1     Running   0          16m    app=nginx2,pod-template-hash=6f69878b4f

NAME                        READY   UP-TO-DATE   AVAILABLE   AGE    LABELS
deployment.apps/mydeploy    1/1     1            1           108m   app=mydeploy
deployment.apps/mydeploy2   1/1     1            1           103m   app=mydeploy2
deployment.apps/nginx       1/1     1            1           138m   app=nginx
deployment.apps/nginx2      1/1     1            1           16m    app=nginx2

NAME                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE    LABELS
service/mydeploy    ClusterIP   10.103.14.10     &lt;none&gt;        80/TCP    108m   app=mydeploy
service/mydeploy2   ClusterIP   10.102.159.245   &lt;none&gt;        80/TCP    103m   app=mydeploy2
service/nginx       ClusterIP   10.110.131.138   &lt;none&gt;        80/TCP    138m   app=nginx
service/nginx2      ClusterIP   10.101.249.45    &lt;none&gt;        80/TCP    16m    app=nginx2
</code></pre>
<pre><code>---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  creationTimestamp: &quot;2023-05-01T18:48:28Z&quot;
  generation: 5
  name: default-deny
  namespace: policy-demo
  resourceVersion: &quot;405350&quot;
  uid: 52f57496-526f-4da0-abf2-a105e43e1c8b
spec:
  podSelector:
    matchLabels:
      app: nginx
  policyTypes:
  - Ingress
  - Egress
status: {}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-allow
  namespace: policy-demo
spec:
  podSelector:
    matchLabels:
      app: mydeploy2
  egress:
    - to:
      - podSelector:
          matchLabels:
            app: mydeploy
  ingress:
    - from:
      - podSelector:
          matchLabels:
            app: mydeploy
  policyTypes:
    - Egress
    - Ingress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-allow-2
  namespace: policy-demo
spec:
  podSelector:
    matchLabels:
      app: mydeploy
  egress:
    - {}
  ingress:
    - {}
  policyTypes:
    - Ingress
    - Egress
</code></pre>
<p>I get a timeout from mydeploy2 to mydeploy</p>
<pre><code>k exec mydeploy2-784fbfd764-mfslq -- curl mydeploy
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:12 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:19 --:--:--     0curl: (6) Could not resolve host: mydeploy
command terminated with exit code 6
</code></pre>
<p>Curl from mydeploy to mydeploy2 works</p>
<pre><code>k exec mydeploy-5865fb49b4-ks7sx -- curl mydeploy2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   615  100   615    0     0   600k      0 --:--:-- --:--:-- --:--:--  600&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to nginx!&lt;/title&gt;
&lt;style&gt;
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Welcome to nginx!&lt;/h1&gt;
&lt;p&gt;If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.&lt;/p&gt;

&lt;p&gt;For online documentation and support please refer to
&lt;a href=&quot;http://nginx.org/&quot;&gt;nginx.org&lt;/a&gt;.&lt;br/&gt;
Commercial support is available at
&lt;a href=&quot;http://nginx.com/&quot;&gt;nginx.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thank you for using nginx.&lt;/em&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
k
</code></pre>

sandeep
<p>was able to get it working with access to dns namespace and pod namespace</p>
<pre><code>  egress:
- to:
    - namespaceSelector:
        matchExpressions:
          - key: kubernetes.io/metadata.name
            operator: In
            values: [ &quot;kube-system&quot;, &quot;policy-demo&quot; ]
</code></pre>
