The Kubernetes network model and CNI

Intermediate · 10 min

Why every Pod gets its own routable IP, the rules a cluster network must meet, and how the container runtime calls a CNI plugin to wire each Pod in.

Before thisPods in depthNodes, the kubelet and the container runtime

CNCF [Cloud Native Computing Foundation] · 12 min · from 1:28

The Kubernetes network model and CNI

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by CNCF [Cloud Native Computing Foundation]Report a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Kubernetes gives every Pod its own IP, and every Pod can reach every other Pod by that IP without NAT. No port mapping, no shared host ports.
  • Containers in one Pod share a network namespace, set up once for the Pod sandbox, so they reach each other on localhost and must not collide on ports.
  • Kubernetes doesn't implement this network. The container runtime calls a CNI plugin (ADD, DEL, CHECK, GC, STATUS) from the config in /etc/cni/net.d, and the plugin wires the Pod in and assigns its IP.
  • Pod IPs usually come from a per-node range: the node IPAM controller hands each Node a podCIDR (a /24 by default), though cloud CNIs often draw from the VPC instead.
  • Plugins differ in how traffic crosses nodes: an overlay such as VXLAN, plain routes or BGP, or real VPC addresses. That choice decides MTU, performance and whether NetworkPolicy works.

The port-mapping problem

On a single Docker host, containers sit on a private bridge and you publish ports: -p 8080:80. That’s fine for one machine. Now picture a hundred machines and ten thousand containers. Every app needs a host port that doesn’t clash with any neighbour, every client has to learn which host and which port, and the app thinks it’s on port 80 while the world sees 31847. Service discovery, firewalls and logs all have to translate.

Kubernetes refuses that whole problem with one rule: every Pod gets its own IP address, and Pods talk to each other directly. A Pod is addressed like a small machine. It listens on its normal port, and anyone in the cluster reaches it at pod-ip:port.

The rules

The network model is a short contract that any cluster network has to meet:

  • Every Pod has its own cluster-wide unique IP (per address family, in dual-stack clusters).
  • A Pod can reach every other Pod, on any node, without NAT. The address the receiver sees is the sender’s real Pod IP.
  • Agents on a node, such as the kubelet, can reach every Pod on that node.

hostNetwork: true Pods are the exception: they share the node’s network namespace and its IP.

Think of it as an office building where every desk has a direct phone number, against a building with one switchboard number and extensions. Kubernetes insists on direct numbers. How the phone company wires the building is left open.

Inside one Pod

Every container in a Pod shares one network namespace (the Linux namespaces lesson explains the kernel side). The runtime creates it once, for the Pod sandbox, before any app container starts, which is why you see a tiny pause container on nodes: it holds the namespace open. So containers in a Pod reach each other on localhost, share one IP and one set of ports, and can’t both bind 8080. That’s what makes sidecars cheap: a proxy in the same Pod is a loopback hop away.

Who builds the network: CNI

Here’s the part that surprises people: Kubernetes doesn’t implement Pod networking at all. Nothing in the API server, scheduler or kubelet moves packets between Pods. A CNI plugin does, and you pick one: Cilium, Calico, Flannel, the AWS VPC CNI, Azure CNI, GKE’s own.

The Container Network Interface is a small spec, now at version 1.1, for how a runtime asks a plugin to attach a container to a network. The flow on a node:

  1. The kubelet asks the container runtime (containerd or CRI-O) over CRI to create a Pod sandbox.
  2. The runtime creates the network namespace and reads the first config in /etc/cni/net.d.
  3. It executes the plugin binary from /opt/cni/bin with CNI_COMMAND=ADD, the namespace path and container ID in environment variables, and the network config on stdin.
  4. The plugin creates the interface (often a veth pair, one end in the Pod and one on the host), calls an IPAM plugin to pick an address, sets routes, and prints the result as JSON on stdout.
  5. The runtime reports the IP back, and it ends up in the Pod’s status.podIPs.

DEL undoes it when the sandbox goes. CHECK verifies it, GC (new in 1.1) cleans up attachments the runtime no longer knows about, and STATUS lets a plugin report that it can’t take new Pods. Note who runs the plugin: the runtime, not the kubelet. The kubelet’s old network-plugin flags went away with dockershim in 1.24.

A typical config, for Flannel delegating to the standard bridge plugin:

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

No config, no Pod network. The runtime then reports NetworkReady=false and the node stays NotReady with cni plugin not initialized. That’s normal on a fresh kubeadm node until you install a plugin, usually as a DaemonSet that drops its binary and config onto every node.

Where Pod IPs come from

Most plugins give each node a slice of the cluster’s Pod range. With --allocate-node-cidrs and a --cluster-cidr, the node IPAM controller in kube-controller-manager writes spec.podCIDRs on each Node, a /24 for IPv4 and a /64 for IPv6 by default. A /24 is 254 usable addresses, comfortably over the kubelet’s default maxPods of 110. The field is write-once. On our lab cluster, a Node created with podCIDRs: [10.244.1.0/24, fd00:10:244:1::/64] refused a later change with node updates may not change podCIDR except from "" to valid. Moving a node to a new range means deleting and re-registering it.

Cloud CNIs often skip this and give Pods real VPC addresses. The AWS VPC CNI attaches ENIs and secondary IPs to the instance, so Pods are first-class on the VPC, but the instance type then limits how many Pods fit.

Crossing nodes

Same-node traffic goes veth to bridge (or eBPF) to veth. Cross-node traffic is where plugins really differ:

  • Overlay. Flannel’s VXLAN mode wraps each Pod packet in UDP (port 8472 on Linux) between nodes. It works on any network, at the cost of 50 bytes of header, hence the 1450 MTU you see in such clusters.
  • Routing. Calico in BGP mode or Flannel’s host-gw installs a route per node’s Pod CIDR, with no encapsulation, which needs a network that will carry Pod addresses.
  • Native VPC. Cloud CNIs, where the underlying network already knows each Pod IP.
  • eBPF dataplanes. Cilium can also replace kube-proxy and enforce policy in the kernel’s eBPF hooks.

The choice matters later in this group: NetworkPolicy is enforced by the CNI, and Flannel alone doesn’t enforce it.

About the video

The embed is a 12-minute clip, 1:28 to 13:15, of “Understanding Kubernetes Networking in 30 Minutes” by Ricardo Katz and James Strong, from the CNCF channel in November 2024. Strong is an ingress-nginx maintainer. The clip covers Linux networking basics, how Pod networking is structured, the Kubernetes networking rules, a Pod networking demo, and the Container Network Interface. The talk goes on to Services, kube-proxy and DNS, which later lessons use. Judged from the chapter list, since transcripts can’t be fetched here. It carries no audio-track flag. It is a KubeCon talk with an English caption track. Simone Rodigari’s 2026 talk in deeper follows a packet from Pod to Pod with captures.

What was run: on a local v1.37.3 control plane with no kubelet and no CNI, we created a dual-stack Node with podCIDRs and saw the write-once rule enforced. Pods there get scheduled but never receive an IP, because nothing runs a sandbox or a plugin. Everything about CNI execution, IPAM and dataplanes is from the CNI 1.1 spec, the Kubernetes network-plugin docs and the controller-manager’s v1.37.3 source (core.go for the /24 and /64 defaults, kubelet defaults for maxPods), checked 2026-11-28.

Where this fits

Pod IPs change every time a Pod is replaced, so nothing should depend on one. Next: Services: ClusterIP, NodePort and LoadBalancer.

Check yourself

  1. 01Two containers in the same Pod both try to listen on port 8080. What happens, and why?

    The second fails with address already in use. They share one network namespace, created for the Pod sandbox, so they share one set of ports and one IP, like two processes on the same machine.

  2. 02A new node joins and stays NotReady with 'container runtime network not ready ... cni plugin not initialized'. What is missing?

    No CNI configuration in /etc/cni/net.d (or no plugin binary). Kubernetes doesn't ship a Pod network. Until a CNI plugin, usually deployed as a DaemonSet, writes its config on the node, the runtime can't set up Pod networking and the kubelet reports the node not ready.

  3. 03Pods on one node can reach each other, but not Pods on another node. Where do you look?

    The cross-node part of the CNI: the overlay tunnel (VXLAN on UDP 8472 for Flannel is often blocked by a firewall or security group), missing routes or BGP sessions, or an MTU mismatch that drops large packets. Same-node traffic only crosses the local bridge or veth, so it works either way.

  4. 04Why does a Pod's IP change when it is recreated, even with the same name?

    The IP belongs to the Pod's network namespace on a particular node, assigned by IPAM from that node's range when the sandbox is created. A new Pod is a new sandbox, often on another node. That's why Services exist.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark