<p>I have a requirement where I'll deploy a pod and when it comes up I need to add some iptable rules inside the pod.
At the same time, I need to add some iptable rules in the worker node on which the pod is running.</p>
<p>If I use &quot;hostNetwork&quot; option for the pod, the iptable rules which I need to add in the pod will also get added to the worker node.</p>
<p>How can this be achieved, where the pod itself adds iptable rules inside the pod as well as in the worker node.</p>

ahmed meraj
<p>Not recommended. ⛔</p>
<p>Basically, the kube-proxy and the network overlay generally heavily use iptables to make things happen in Kubernetes. Adding your own iptables could work but you would have to watch everything Kubernetes does and make sure anything you do doesn't conflict.</p>
<p>There is no specific tool that would help manage all of the iptables that Kubernetes creates along with the ones you create. This would only work at the node level. There isn't such a thing as adding iptables at the pod level.</p>
<p>You could use some of the networking objects like <a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/" rel="nofollow noreferrer">Network Policies</a> to restrict traffic or if you are using Calico you can use a more <a href="https://docs.projectcalico.org/reference/resources/networkpolicy" rel="nofollow noreferrer">advanced version of it</a>.</p>
<p>Another option is just to have an external firewall that restrict some traffic to your nodes in your Kubernetes cluster.</p>
<p>✌️</p>
