<p>how to ban network in k8s container?</p>

<p>I used k8s to exec some third-party code, and it may be unsecure.</p>

<p>So I use two container(A and B) in one pod, A to get code and pass to B container, B to exec it.</p>

<p>To protect our network, I'd like to disable B's network. But I didn't find any method work.</p>

<p>Methods I have tried:</p>

<ol>
<li><p>ifconfig eth0 down, ifdown eth0</p></li>
<li><p>iptables -P INPUT DROP, iptables -P OUTPUT DROP</p></li>
</ol>

<p>Is there any other methods?</p>

<p>UPDATE:
finally, I use iptable to disable network of a user, then switch to the user in container B to execute the code.</p>

<p>Notice: As the network namespace of the two container is the same, iptable rules will take effect in the two container.</p>

Zhou
<p>Better not touch the Iptable rules which may cause network connectivity issues  in K8s. Try <a href="https://docs.docker.com/network/none/" rel="nofollow noreferrer">Network Policy</a> in K8s to isolate the pod, kind of disabling network for pods. It is like disabling the <a href="https://docs.docker.com/network/none/" rel="nofollow noreferrer">network for container in docker</a></p>
<p><strong>UPDATE</strong></p>
<p>Also I understood that the pod contains 2 containers(A&amp;B). I think, it not possible to disable networking only for container <code>B</code> in that pod.</p>
