Octet

Explain the Kubernetes networking model. How do pods on different nodes talk to each other?

Show the answer

Say this first

Every pod gets its own IP, and every pod can reach every other pod on any node without NAT. Each node gets a slice of the pod CIDR, often a /24. The CNI plugin creates the pod's interface, assigns the IP and makes the cross-node path work, either with an overlay (VXLAN or IP-in-IP), with plain routing (BGP or cloud route tables), or by giving pods real VPC addresses like the AWS VPC CNI and Azure CNI do.

Go deeper

Inside a node

Each pod has its own network namespace. The CNI plugin creates a veth pair: one end is eth0 in the pod, the other sits on the host, attached to a bridge or routed by the host. Containers in one pod share the namespace and talk over localhost.

Between nodes

ApproachHowExamples
OverlayEncapsulate pod packets between node IPsFlannel VXLAN, Calico VXLAN or IP-in-IP, Cilium VXLAN or Geneve
RoutedAdvertise each node's pod CIDRCalico with BGP, cloud route tables
VPC-nativePods get VPC addresses, the cloud fabric routes themAWS VPC CNI, Azure CNI, GKE VPC-native (alias IPs)

Overlay works anywhere but adds encapsulation overhead and lowers the pod MTU. VPC-native avoids the overlay and makes pods first-class in security groups and flow logs, but uses VPC addresses fast.

What CNI is

The Container Network Interface is a spec and a set of plugins. The container runtime calls the plugin with ADD and DEL when a pod sandbox is created or removed. The plugin handles interface setup and IPAM. Network policy enforcement is a separate capability that some CNIs provide (Calico, Cilium) and others do not (Flannel on its own).

Three ranges to plan

Node addresses, the pod CIDR and the service CIDR. None of them may overlap with each other or with networks pods must reach.

Traps

  • Saying pods talk through NAT by default. The model requires no NAT between pods.
  • Forgetting that the pod CIDR must not overlap with on-prem networks the pods call.
How did you do?Book Perspective: Virtual Networks All the Way Down