IPAM and Pod CIDR Allocation

Pods on many Nodes take IPs from one cluster range at once, yet no two get the same address. Who keeps two Nodes from handing out one IP, where does each Pod IP come from, and when does a Node get its range?

Play the animation 4 steps, animated, plays on a computer or a tablet

IPAM and Pod CIDR Allocation diagram: IPAM and Pod CIDR allocation, where the controller-manager carves a non-overlapping slice

IPAM and Pod CIDR Allocation, step by step

  1. The cluster pod CIDR is set on the controller-manager with the --cluster-cidr flag. It is the single pool every Node slice is carved from, and on its own it belongs to no Node yet.

    Play from step 1
  2. With --allocate-node-cidrs set, the controller-manager carves a smaller, non-overlapping block out of the pool for every Node and writes it into node.spec.podCIDR. The block size comes from --node-cidr-mask-size, /24 by default, so Node-1 owns 10.244.1.0/24, Node-2 owns 10.244.2.0/24 and Node-3 owns 10.244.3.0/24.

    Play from step 2
  3. When a Pod is scheduled to Node-1, a CNI IPAM that uses the Node podCIDR draws the Pod address strictly from that slice, 10.244.1.0/24, so the Pod gets 10.244.1.5. Allocation never reaches outside the block a Node owns, which is what stops two Nodes from colliding.

    Play from step 3
  4. Every other Node assigns the same way, out of its own slice. A Pod scheduled to Node-2 gets 10.244.2.8 from 10.244.2.0/24, a different /24 that can never overlap the addresses on Node-1. Node-3 holds 10.244.3.0/24 with no Pod scheduled on it yet, because a block is carved at Node registration. So every Pod IP drawn from these blocks is unique across the whole cluster, which is what lets any Pod be reached directly while routing only has to track which Node owns which /24.

    Play from step 4

Sources