<p>In kubernetes network policy we can set Ingress value as blank array i.e. [] or we can also set value as - {}</p>

<p>What is the difference between using these 2 values?</p>

<p><strong>First YAML that I tried - It didn't work</strong></p>

<pre><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: internal-policy
spec:
  podSelector:
    matchLabels:
      name: internal
  policyTypes: ["Ingress","Egress"]
  ingress: []
  egress:
  - to:
    - podSelector:
        matchLabels:
          name: mysql
    ports:
    - protocol: TCP
      port: 3306
</code></pre>

<p>Second YAML that was answer in katacoda scenario</p>

<pre><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: internal-policy
  namespace: default
spec:
  podSelector:
    matchLabels:
      name: internal
  policyTypes:
  - Egress
  - Ingress
  ingress:
    - {}
  egress:
  - to:
    - podSelector:
        matchLabels:
          name: mysql
    ports:
    - protocol: TCP
      port: 3306
</code></pre>

vikas sharma
<p>In both cases you have specified <strong>Policy Types: Ingress and Egress</strong></p>

<ol>
<li>In the first example:</li>
</ol>

<pre><code>     ingress: []
</code></pre>

<p>this rule (is empty) and <strong>deny all ingress traffic</strong>, (the same result if ingress rule are not present in the spec).</p>

<p>You can verify this by running:</p>

<pre><code>kubectl describe networkpolicy internal-policy 

Allowing ingress traffic:
    &lt;none&gt; (Selected pods are isolated for ingress connectivity)
</code></pre>

<ol start="2">
<li>In the second example:</li>
</ol>

<pre><code>     ingress:
        - {}
</code></pre>

<p>this rule <strong>allow all ingress traffic</strong>:</p>

<pre><code>kubectl describe networkpolicy internal-policy 

 Allowing ingress traffic:
    To Port: &lt;any&gt; (traffic allowed to all ports)
    From: &lt;any&gt; (traffic not restricted by source)
</code></pre>

<p>As per documentation: <a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/" rel="nofollow noreferrer">Network Policies</a></p>

<blockquote>
  <p>Ingress rules:
  Each NetworkPolicy may include a list of whitelist ingress rules. Each rule allows traffic which matches both the from and ports sections.</p>
</blockquote>

<p>Hope this help.</p>
