The Kubernetes Network Model

Kubernetes defines a Pod network model that lets Pods in a cluster communicate with each other, whether they are on the same Node or on different Nodes.

Its main properties are:

  • Pod-to-Pod: Pods can reach each other by Pod IP.
  • Node-to-Node: Nodes must have working network connectivity between them to carry cross-Node Pod traffic.
  • Identifiable Pod IPs: every Pod has its own IP, which can be the source or destination address of a packet.
  • No NAT: in the normal direct Pod-to-Pod model, Pod IPs do not need to be NATed just because traffic crosses Nodes.

This is the behavior the Kubernetes network model aims for, but Kubernetes itself does not set up all the underlying networking. A network implementation is still needed to provide the connectivity.


Suppose the cluster has two Nodes:

Node Node IP
Node A 192.168.1.10
Node B 192.168.1.20

Each Node runs one Pod:

Pod Node Pod IP
Pod A Node A 10.244.1.2
Pod B Node B 10.244.2.3

CNI in Kubernetes

When Pod A connects to Pod B, knowing that Pod B's IP is 10.244.2.3 is not enough. The network still has to answer these questions:

  1. How is the Pod's network interface created?
  2. How are Pod IPs assigned without conflicts?
  3. How does Node A send the packet to Node B?
  4. How does Node B forward the packet to the right Pod?
  5. How are routes managed, and how is the transport method chosen?

Assigning IPs alone does not solve these, so a container networking mechanism is needed to create and manage Pod networking.

What Is CNI?

CNI (Container Network Interface) is a specification for container networking. It defines how container network plugins are invoked and how they carry out network operations.

Plugins in the CNI ecosystem can handle, or help with:

  • Creating the Pod's network interface.
  • Assigning the Pod IP.
  • Setting up network routes.
  • Providing Pod connectivity across Nodes.
  • Working with other components to provide network policy and packet filtering.

Common Kubernetes networking solutions include Flannel, Calico and Cilium. Their features and implementations differ.


How Does Pod-to-Pod Communication Work?

Pods on the Same Node

When two Pods are on the same Node, packets travel through that Node's network interfaces and virtual network devices.

Common network building blocks include:

  • Network namespace: isolates the Pod's network environment.
  • veth pair: a pair of virtual Ethernet interfaces connecting two network environments.
  • Linux bridge or another forwarding mechanism: forwards packets, depending on how the CNI is implemented.

The conceptual flow:

The actual path depends on the CNI, the routing setup and the network mode.

Pods on Different Nodes

When Pod A and Pod B are on different Nodes, packets have to travel over the network between the Nodes.

Assume:

  • Pod A: 10.244.1.2
  • Pod B: 10.244.2.3
  • Node A: 192.168.1.10
  • Node B: 192.168.1.20

The flow is:

  1. Pod A sends a packet to destination IP 10.244.2.3.
  2. Node A decides how to send the packet based on its routes and network settings.
  3. The CNI solution delivers the packet to Node B, using native routing, an overlay network or similar.
  4. Node B receives the packet and forwards it to Pod B.
  5. Pod B receives the packet and replies.

For steps 2 and 3 to work, each Node usually gets its own slice of the Pod network (a Pod CIDR). For example, the whole cluster uses 10.244.0.0/16, which is split among the Nodes:

Node Node IP Pod CIDR
Node A 192.168.1.10 10.244.1.0/24
Node B 192.168.1.20 10.244.2.0/24

Then the range a destination IP falls into tells you which Node the Pod is on. The most intuitive approach is to add a static route on each Node saying "the other side's Pod range goes to the other side's Node IP":

# Node A
ip route add 10.244.2.0/24 via 192.168.1.20

# Node B
ip route add 10.244.1.0/24 via 192.168.1.10

The path the packet actually takes:

  1. Pod A's packet leaves through eth0 inside the Pod and reaches the bridge on Node A through the veth pair.
  2. Node A looks up its routing table. 10.244.2.3 matches 10.244.2.0/24 via 192.168.1.20, so the packet goes out of Node A's eth0 to Node B.
  3. Node B looks up its own routing table. 10.244.2.0/24 is the local bridge, so the packet goes through the bridge and veth into Pod B.

Throughout the whole trip, the source and destination stay 10.244.1.2 → 10.244.2.3 and are never NATed. That is the No NAT property mentioned earlier.

The key point: Pod A's destination is Pod B's IP; it does not have to connect to some application port on Node B first. The network between the Nodes carries the packet, and the destination Node hands it to the right Pod.

Why Not Just Add the Routes Yourself?

With two Nodes, adding routes by hand is easy enough, but real clusters run into:

  • Routes grow with the number of Nodes: with N Nodes, every Node maintains N-1 routes, and all of them need updating whenever a Node joins or leaves.
  • Nodes must share an L2 segment: via 192.168.1.20 requires the next hop to be directly reachable. When Nodes span subnets or data centers, the routers in between do not know about 10.244.x.x.
  • Cloud networks block it: many cloud VPCs drop packets whose source or destination IP does not belong to the VM by default (for example, AWS's Source/Destination Check).
  • Pod lifecycle: every new Pod needs a network namespace, a veth pair and an IP, and all of that has to be reclaimed when the Pod is deleted.

This repetitive, error-prone work is what CNI plugins automate.


Crossing Nodes: Native Routing and Overlays

CNIs broadly use one of two ways to carry traffic between Nodes.

Native Routing

This is what the diagram above shows: Pod packets are routed directly between Nodes without extra wrapping. The difference is that the routes are not added by hand; the CNI generates and syncs them automatically:

  • Flannel host-gw mode: flanneld writes routes for the other Nodes' Pod CIDRs on every Node. The Nodes must be on the same L2 segment.
  • Calico BGP mode: a BGP agent (BIRD) on every Node exchanges routes with the others. It can also peer with physical routers in the data center so the outside network knows about the Pod ranges too.

The upside is no encapsulation overhead, good performance, and packet captures that show the Pod IPs directly. The downside is that the underlying network must be willing to forward packets with Pod IPs.

Overlay Network

When the underlying network does not know about Pod IPs, the whole Pod packet is wrapped inside another packet whose source and destination are Node IPs:

Outer: 192.168.1.10 → 192.168.1.20 (UDP 8472, VXLAN)
  Inner: 10.244.1.2 → 10.244.2.3 (the original Pod packet)

Node B strips the outer layer and hands the inner packet to Pod B. The underlying network only sees ordinary traffic between Nodes.

Common encapsulation methods:

  • VXLAN: Flannel's default mode, also supported by Calico and Cilium.
  • IP-in-IP: Calico's traditional encapsulation, with a smaller extra header.

The upside is that it asks almost nothing of the underlying network and works across subnets and in the cloud. The cost is an extra header on every packet (about 50 bytes for VXLAN), so the Pod MTU has to be reduced accordingly, plus the CPU cost of encapsulating and decapsulating.

Native routing Overlay
Encapsulation None VXLAN, IP-in-IP and so on
Underlying network requirement Must forward Pod IPs Nodes just need to reach each other
Performance Better Encapsulation overhead
MTU Same as the Node Minus the encapsulation header
Common examples Flannel host-gw, Calico BGP Flannel VXLAN, Calico VXLAN / IPIP

How Are CNI Plugins Invoked?

CNI plugins are executables on the Node, not long-running services. Creating a Pod goes roughly like this:

  1. kubelet asks the container runtime (such as containerd) through the CRI to create the Pod sandbox.
  2. containerd creates the Pod's network namespace.
  3. containerd reads the config files in /etc/cni/net.d/ and, according to them, calls the matching plugin in /opt/cni/bin/ with the ADD command.
  4. The plugin creates a veth pair, puts one end into the Pod's namespace, then calls an IPAM plugin (such as host-local) to assign an IP and set up routes.
  5. The plugin returns the result (the Pod IP and so on) to containerd, which reports back to kubelet.

When the Pod is deleted, the plugin is called with DEL to reclaim the IP and network interface.

Taking Flannel as an example, installing it creates /etc/cni/net.d/10-flannel.conflist on every Node:

{
  "name": "cbr0",
  "cniVersion": "0.3.1",
  "plugins": [
    {
      "type": "flannel",
      "delegate": {
        "hairpinMode": true,
        "isDefaultGateway": true
      }
    },
    {
      "type": "portmap",
      "capabilities": {
        "portMappings": true
      }
    }
  ]
}

type is the name of an executable in /opt/cni/bin/. The flannel plugin hands the actual work to the bridge and host-local plugins, which is why the CNI plugins have to be in place when installing the cluster.

This also explains why Nodes stay NotReady after building a cluster with kubeadm and before installing a CNI: there is no config file in /etc/cni/net.d/, so the container runtime reports that the network is not ready.

CNI does not handle Services

CNI only handles the Pod's network interface, IP and connectivity. Service ClusterIPs and load balancing are handled by kube-proxy (or a kube-proxy replacement such as Cilium), which is a separate layer.


Common CNIs: Flannel, Calico, Cilium

Flannel Calico Cilium
flannel-logo project-calico calico-logo
Cross-Node transport VXLAN (default), host-gw BGP native routing, VXLAN, IP-in-IP VXLAN, Geneve, native routing
NetworkPolicy Not supported Supported, plus its own extended policies Supported, up to L7
Data plane Linux bridge + routes iptables / nftables or eBPF eBPF
Replaces kube-proxy No Yes, in eBPF mode Yes
Best for Testing, simple clusters Clusters that need NetworkPolicy or integration with the physical network Large clusters, observability needs (Hubble)

A few implementation differences:

  • Flannel creates a cni0 bridge and a flannel.1 VXLAN interface on each Node. It is the closest to the model in the diagrams above, which makes it good for understanding the principles.
  • Calico does not use a bridge. Instead it adds a /32 route on the host for each Pod's veth (the cali* interfaces). It also manages IPAM itself, handing out /26 blocks to Nodes, which do not necessarily follow the Node's spec.podCIDR.
  • Cilium uses eBPF in the kernel for packet forwarding, policy and Service load balancing, and can work entirely without iptables.

Observing It in a Cluster

See the Pod CIDR assigned to each Node:

kubectl get nodes -o custom-columns=NAME:.metadata.name,PODCIDR:.spec.podCIDR

See Pod IPs and the Nodes they run on:

kubectl get pods -o wide

Look at the CNI config and plugins on a Node:

ls /etc/cni/net.d/
ls /opt/cni/bin/

Look at the routing table on a Node to see the routes the CNI added. With Flannel VXLAN, for example:

ip route
# 10.244.0.0/24 via 10.244.0.0 dev flannel.1 onlink
# 10.244.1.0/24 dev cni0 proto kernel scope link src 10.244.1.1
# 10.244.2.0/24 via 10.244.2.0 dev flannel.1 onlink

The local Pod range goes through the cni0 bridge, while other Nodes' ranges go through flannel.1, that is, VXLAN encapsulation. Compared with the manual ip route add earlier, the idea is the same; only the next hop is now the VXLAN interface, and flanneld maintains it automatically.

Finally, test connectivity between Pods on two different Nodes:

kubectl run pod-a --image=busybox --restart=Never -- sleep 3600
kubectl run pod-b --image=busybox --restart=Never -- sleep 3600
kubectl get pods -o wide

kubectl exec pod-a -- ping -c 3 <pod-b IP>

💡 Pinning a Node

If both Pods land on the same Node, add --overrides='{"spec":{"nodeName":"<node name>"}}' to kubectl run to choose the Node.


Summary

  • Kubernetes only defines the network model: every Pod has its own IP and Pods can reach each other without NAT. The actual networking is done by a CNI plugin.
  • Pods on the same Node reach each other through veth pairs and a bridge (or routes).
  • Across Nodes, each Node owns a Pod CIDR, and packets reach the destination Node through native routing or an overlay (VXLAN, IP-in-IP).
  • Adding static routes by hand shows the principle but does not scale with the cluster; the CNI creates interfaces, assigns IPs and maintains routes automatically.
  • CNI plugins are executables in /opt/cni/bin/ that the container runtime calls according to the config in /etc/cni/net.d/.
  • When choosing a CNI, the most common considerations are whether you need NetworkPolicy, whether the underlying network can forward Pod IPs, and your performance and observability requirements.

References

  1. CNI - The Container Network Interfacecni.dev
  2. ITNEXT - Container Network Interface (CNI) in Kubernetes: An Introductionitnext.io
  3. flannelgithub.com
  4. Calicogithub.com
  5. ciliumcilium.io