<p>I want to deny all egress traffic . So I created this network policy </p>

<pre><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny
spec:
  podSelector: {}
  policyTypes:
  - Egress
</code></pre>

<p>And then i applied it to namespace </p>

<p>kubectl -n pps-api-gateway-ci apply -f ~/Documents/networkpolicy.yaml</p>

<p>to test this , I did describe networkpolicy</p>

<pre><code>    kubectl -n pps-api-gateway-ci describe networkpolicy
    Name:         default-deny
    Namespace:    pps-api-gateway-ci
    Created on:   2018-05-29 13:50:52 -0700 PDT
    Labels:       &lt;none&gt;
    Annotations:  kubectl.kubernetes.io/last-applied-configuration= 
   {"apiVersion":"networking.k8s.io/v1","kind":"NetworkPolicy","metadata": 
   {"annotations":{},"name":"default-deny","namespace":"pps-api-gateway- 
   ci"},"spec"...
   Spec:
      PodSelector:     &lt;none&gt; (Allowing the specific traffic to all pods in this 
    namespace)
      Allowing ingress traffic:
        &lt;none&gt; (Selected pods are isolated for ingress connectivity)
       Allowing egress traffic:
        &lt;none&gt; (Selected pods are isolated for egress connectivity)
       Policy Types: Egress
</code></pre>

<p>then i logged into that container </p>

<p>ping www.google.com</p>

<pre><code>PING www.google.com (216.58.217.100): 56 data bytes
64 bytes from 216.58.217.100: icmp_seq=0 ttl=46 time=2.552 ms
64 bytes from 216.58.217.100: icmp_seq=1 ttl=46 time=1.835 ms
64 bytes from 216.58.217.100: icmp_seq=2 ttl=46 time=1.487 ms
64 bytes from 216.58.217.100: icmp_seq=3 ttl=46 time=2.523 ms
64 bytes from 216.58.217.100: icmp_seq=4 ttl=46 time=1.607 ms
64 bytes from 216.58.217.100: icmp_seq=5 ttl=46 time=1.480 ms
</code></pre>

<p>I should not be able to ping if my egress policy is applied.</p>

<p>I am working with kubernetes 1.9.6 version</p>

Priyanka Gandhi
<p>From the <a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/" rel="nofollow noreferrer">official documentation</a>:</p>

<blockquote>
  <p>Network policies are implemented by the network plugin, so you m<strong>ust be using a networking solution</strong> which supports NetworkPolicy - <strong>simply creating</strong> the resource without a controller to implement it will <strong>have no effect</strong>.</p>
</blockquote>

<p>A number of networking plugins, including <a href="https://kubernetes.io/docs/tasks/configure-pod-container/calico-network-policy/" rel="nofollow noreferrer">Calico</a> and <a href="https://kubernetes.io/docs/tasks/configure-pod-container/weave-network-policy/" rel="nofollow noreferrer">Weave Net</a>, support using <code>Network Policies</code>, but <a href="https://github.com/coreos/flannel" rel="nofollow noreferrer">Flannel</a>, for example, doesn’t.</p>
