Network Namespaces
A Pod usually acts like a separate machine, with its own address, routes and free ports. What gives a Pod this network stack, what does its second container get, and what is left of the stack once the Pod is deleted?
Play the animation 4 steps, animated, plays on a computer or a tablet
Network Namespaces, step by step
-
When the Pod sandbox starts, the runtime creates a brand new network namespace and the pause container holds it for the life of the Pod. Only a Pod that sets hostNetwork goes without one. The stack inside is empty: one loopback device, no routes, no rules and every port still free. Nothing reaches in or out yet.
Play from step 1 -
The CNI plugin then joins the namespace to the outside with a veth pair, and the in-Pod end of that pair appears in this stack as eth0. A default route is written through eth0, so that one cable becomes the path between the Pod and everything outside. Plugins that hand the Pod other devices are the exception.
Play from step 2 -
A second container does not get a stack of its own, it enters this one. Both of them sit on the same four layers, which is why a second eth0 and a second set of ports never appear, and why each of them reaches the other over the loopback without leaving the Pod.
Play from step 3 -
Because the stack is separate, the routing table and packet rules inside it belong to this Pod alone, and a port bound here does not collide with the Node. When the Pod is deleted, the runtime calls CNI DEL to release the address and remove the veth, and the namespace goes with the Pod.
Play from step 4