<p>Context: I am using EKS with calico plugin for network policies, and a managed node group.</p>
<p>I have a namespace called &quot;simon-test&quot; in which I want to deny all egress from the namespace to others (so pods in simon-test will not be able to see other pods in other namespaces). I tried to do this using the following network policy (which seems to work as expected):</p>
<pre><code>kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  name: default-deny-all-egress
  namespace: simon-test
spec:
  policyTypes:
  - Egress
  podSelector: {}
  egress: []
</code></pre>
<p>but this also blocked all the internal networking within the namespace. So in order to fix this, I created another network policy that is supposed to allow all traffic within the namespace:</p>
<pre><code>kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  name: allow-internal
  namespace: simon-test
spec:
  podSelector:
    matchLabels: {}
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          name: simon-test
</code></pre>
<p>But this doesn't solve the problem, as there is still no networking within the namespace.
I am curious why I can still reach &quot;simon-test&quot; from another pod in another namespace though (I am running <code>nc -nlvp 9999</code> in a pod in &quot;simon-test&quot; and <code>nc -z ip-of-pod-in-simon-test-ns 9999</code> from a pod from another namespace and it can reach it, but when pinging the pod from within simon-test it can't.)</p>

Simon Ernesto Cardenas Zarate
<p>I am not sure exactly about the internals of calico / network policies, but I was able to solve this as follows:</p>
<pre><code>  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          name: simon-test
</code></pre>
<ol>
<li><p>The above ingress rule was not working, because the namespace had no &quot;name=simon-test&quot; label on
it. I thought by default all namespaces had a label called &quot;name&quot; that
you can reference from here, but it doesn't seem to be the case. To
solve this I had to add a label:
<code>kubectl label ns simontest name=simon-test</code>.</p>
</li>
<li><p>For the second problem: <code>I am curious why I can still reach &quot;simon-test&quot; from another pod in another namespace though (when ingress was blocked)</code> it was because I was trying to reach &quot;simon-test&quot; ns from a pod in kube-system, which happened to be using hostNetwork enabled, hence the IP address that the pod had assigned, happened to be the IP address of the k8s node, (and not an IP of a pod, apparently network policies can tell apart when an IP is assigned to a pod and a k8s node?) hence not being filtered by the network policy.</p>
</li>
</ol>
