Kubernetes pod networking model — requirements
Kubernetes defines a simple, powerful pod networking model. Any networking solution must satisfy these requirements:- Every pod gets a unique, routable IP address.
- A pod can reach every pod on the same node using that IP.
- A pod can reach every pod on other nodes using that IP.
- Pod-to-pod communication must not require NAT.
Kubernetes does not mandate specific IP ranges. You can choose any private address space, but the CNI implementation must automatically assign IPs and configure connectivity across nodes so those IPs are routable cluster-wide.
Understanding how a CNI plugin satisfies these requirements requires basic knowledge of Linux networking primitives: network namespaces, veth pairs, bridges, and routing.
Building block: network namespaces, veth pairs and bridges
On Linux, you can implement pod networking with network namespaces and veth pairs. At a high level, each node performs:- Create a node-level L2 device (a bridge, VXLAN device, or other datapath) and give it an IP/gateway for that node’s pod-subnet.
- For each pod, create a veth pair. Place one end in the pod’s network namespace and attach the other end to the node datapath.
- Assign the pod IP in the pod-subnet and set a default route via the node datapath IP.
- Ensure routing between pod-subnets across nodes.
10.244.1.0/24 as its pod subnet.
10.244.1.0/24 on node1, 10.244.2.0/24 on node2), pods on the same node can now reach each other. The next step is to enable cross-node routing so pod IPs on different nodes can reach one another.
Inter-node routing: simple static approach
To reach a pod on another node, each host must know how to route to that node’s pod subnet. If pod10.244.1.2 on node1 wants to reach pod 10.244.2.2 on node2, node1 needs a route for 10.244.2.0/24 via node2’s host IP (for example 192.168.1.12):
- Program routes centrally on the cluster router (aggregate per-node subnets into a single route such as
10.244.0.0/16). - Use an overlay (VXLAN, GRE) to encapsulate pod traffic between hosts.
- Use a routing-based datapath (BGP/MPLS) where nodes advertise pod subnets automatically.
Automating the per-pod steps: where CNI fits in
The manual sequence we ran for each pod (create veth, move into namespace, attach to bridge, assign IP, configure route) must be performed automatically and coordinated with the container runtime. Thousands of pods can be created or destroyed per minute, so this process must be programmatic and reliable. The Container Network Interface (CNI) is the integration layer between Kubernetes (the kubelet and container runtime) and the network implementation. The runtime invokes a CNI plugin binary for pod lifecycle events and provides JSON configuration on stdin describing the pod, namespace, and desired network. The plugin performs the networking work and returns the result (including the allocated IP) to the runtime. A minimal set of actions a CNI plugin typically performs on ADD (attach a pod to the network):- Create a veth pair.
- Move one end into the pod’s network namespace.
- Attach the host end to the node datapath (bridge, VXLAN device, or kernel datapath).
- Allocate and assign a pod IP from IPAM.
- Set up the pod’s default route and any necessary iptables rules.
ip -n <namespace> ... or ip netns exec <namespace> ... when operating inside a network namespace.
CNI plugins commonly include an IPAM (IP address management) component and implement different datapaths — Linux bridge, VXLAN overlay, host-gw with routing, BGP-based routing, or eBPF datapaths. Choose a CNI that matches your cluster scale, performance, and operational model.
How the container runtime invokes CNI
Kubelet (or the container runtime) is configured with a CNI configuration file and a filesystem path to the CNI plugin binaries. For a pod lifecycle event:- Kubelet prepares the JSON configuration describing the pod: pod name, namespace, container ID, and network configuration.
- Kubelet executes the CNI binary with the
ADDcommand and passes the JSON on stdin. - The CNI plugin allocates/configures the network interface(s), programs routes and firewall rules as needed, and returns a JSON result with the assigned IP.
- On pod deletion, kubelet calls the CNI binary with
DELso the plugin can tear down the interface and release the IP.
Summary
- Kubernetes requires each pod to have a routable IP and peer-to-peer connectivity across nodes without NAT.
- Pod networking in Linux is built from primitives: network namespaces, veth pairs, bridges or other datapaths, and routes.
- Inter-node routing can be handled with static host routes, a centralized router, overlays (VXLAN), or dynamic routing (BGP). CNIs automate these choices for you.
- The CNI specification standardizes how kubelet and the container runtime call network plugins to attach/detach pod interfaces and manage IP addresses.
Links and references
- Kubernetes Networking Concepts
- CNI (Container Network Interface) project
- Linux network namespaces and veth pairs (man ip-netns, ip-link)