<p>i'ams truggle with writing K8s network policy to deny trafic from pod to pod, pod must be specefied by label or name.</p>

<p>Can some one help me?</p>

<p>I'am not are devops/sys admin. And i need this for Integration Testting.
I check <a href="https://github.com/ahmetb/kubernetes-network-policy-recipes" rel="nofollow noreferrer">https://github.com/ahmetb/kubernetes-network-policy-recipes</a> examples. But still can't do it. </p>

<p>Here is exampel that allow acces from only one service </p>

<pre><code>kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  name: api-allow
spec:
  podSelector:
    matchLabels:
      app: bookstore
      role: api
  ingress:
  - from:
      - podSelector:
          matchLabels:
            app: bookstore
</code></pre>

<p>But i need oposite things, denny only from one pod.</p>

Grigoriev Nick
<p>you should define two network policies as mentioned below</p>

<ol>
<li>default deny all traffic</li>
<li>allow the traffic to a  pod from other pods/namespaces</li>
</ol>

<p>here are some good recipes that would be helpful. follow the link
<a href="https://github.com/ahmetb/kubernetes-network-policy-recipes" rel="nofollow noreferrer">network policy recipes</a></p>
