Beginners guide to container-to-container networking

Alex Jones avatar
By Alex Jones


Learn how containers within a pod in Kubernetes communicate with each other through network namespaces on the Linux host.



Welcome to this video about container-to-container networking for Kubernetes. Let's start by reminding ourselves what a node looks like in Kubernetes. It typically would have a virtual machine. This virtual machine would have a kubelet running on top of it, and that kubelet would be scheduling containers via its Container Runtime Interface. A container, as represented here, forms part of a pod, and a pod is a collection of one or more containers, a pod being the smallest atomic unit of deployment in Kubernetes. But how do these containers talk to each other? That's where we need to understand a concept from the Linux host.

How does container to container networking take place?

Firstly, we have an ethernet device that allows for network traffic in and out of the virtual machine. But on top of this, we have a network namespace. Network namespace is the ability to partition the network layer into isolated stacks per process. Hence, we have a root network namespace, but what we're going to do is when we create a new pod, we define the pod as having its own network namespace. So, in this occurrence, we'll call it mypodns which approximately amounts to /var/run/netns/mypodns as a file directory path, and that is a mount point for the processes from our containers.

This also means the second part is that when we launch a container, we have to rely upon the docker command of the net container function to link these containers into the pod network namespace. This means the pods can communicate as if they're on the local host. In conjunction with this, the mypod network namespace is attached to the root network namespace, allowing communication with the outside world.

In the following video, we will look at how we talk between multiple pods on the same host. Thank you.

Don't stop now, check out your next lesson