Skip to content
LF Cert Trainer

Lesson 113 · Section 9: Networking

Lesson 113: IPAM: how every Pod gets a unique IP address (with Weave Net as the example)

Who hands out Pod IP addresses and how duplicates are avoided: the ipam part of a CNI configuration, per-node ranges with host-local, cluster-wide pools as in Weave Net and Calico, and the commands that reveal the Pod range, a node's share and a Pod's gateway in any cluster. · 18 min read · 3 min video

1/9IP address management
0:00 / 2:48

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why IP address management is a problem at all

The previous lesson showed that the container runtime runs a CNI plugin for every new Pod. Part of that job is to give the Pod an IP address, and the Kubernetes network model adds a hard condition: the address must be unique in the whole cluster, because Pods talk to each other by those addresses without NAT.

On one machine that is easy: keep a list. In a cluster, three nodes may each start ten Pods in the same second. If each node just picked "the next free address" from the same range, two Pods would end up with 10.244.0.5, and traffic for one would reach the other.

Keeping track of which addresses exist, which are taken and who may hand out which is called IP address management (IPAM). Kubernetes does not do it for Pods. The network plugin does.

What it is

The main plugin delegates the address to an IPAM pluginrunsIP pleaserecords 10.244.1.7assignscontainerdADD for Pod webMain pluginbridge, flannel...IPAM pluginhost-localPod webeth0 10.244.1.7State on the nodeone file per IP
The main plugin delegates the address to an IPAM plugin. Wiring and addressing are two jobs. The main plugin builds the interface and asks the plugin named in the ipam section for an address.

Parts:

  • containerd (ADD for Pod web)
  • Main plugin (bridge, flannel...)
  • IPAM plugin (host-local)
  • Pod web (eth0 10.244.1.7)
  • State on the node (one file per IP)

Connections:

  • containerd to Main plugin: runs
  • Main plugin to IPAM plugin: IP please
  • IPAM plugin to State on the node: records 10.244.1.7
  • Main plugin to Pod web: assigns

The CNI standard separates two jobs:

  • The main plugin (bridge, flannel, calico, weave-net) creates the interface and connects it.
  • The IPAM plugin decides which address, gateway and routes that interface gets.

The main plugin finds its IPAM plugin in the ipam section of the configuration in /etc/cni/net.d:

{
  "type": "bridge",
  "bridge": "cni0",
  "ipam": {
    "type": "host-local",
    "subnet": "10.244.1.0/24",
    "routes": [{ "dst": "0.0.0.0/0" }]
  }
}

ipam.type is, once more, the name of a binary in /opt/cni/bin.

IPAM pluginHow it worksWhere you meet it
host-localHands out addresses from a range given in the configuration. Remembers them in files on the nodeFlannel, the plain bridge plugin, many simple setups
dhcpAsks a DHCP server on the networkPods attached to an existing physical network
staticUses the address written in the configurationSpecial cases and tests
calico-ipamTakes small blocks from a cluster-wide pool stored in the Kubernetes APICalico
built into the agentThe plugin's own daemon keeps the poolWeave Net, Cilium

How it works

Design 1: every node owns a slice

Design 1: every node owns a slicepodCIDRpodCIDRpodCIDRhost-localCluster Pod range10.244.0.0/16controlplane10.244.0.0/24node0110.244.1.0/24node0210.244.2.0/24Pods on node0110.244.1.2 to .254
Design 1: every node owns a slice. The cluster range is cut into one fixed subnet per node. Each node hands out addresses from its own slice without asking anyone, so two nodes can never pick the same address.

Parts:

  • Cluster Pod range (10.244.0.0/16)
  • controlplane (10.244.0.0/24)
  • node01 (10.244.1.0/24)
  • node02 (10.244.2.0/24)
  • Pods on node01 (10.244.1.2 to .254)

Connections:

  • Cluster Pod range to controlplane: podCIDR
  • Cluster Pod range to node01: podCIDR
  • Cluster Pod range to node02: podCIDR
  • node01 to Pods on node01: host-local

The cluster gets one large Pod range, for example 10.244.0.0/16. It is cut into equal subnets, one per node, and each node only ever uses its own. Nobody has to coordinate at Pod creation, and collisions cannot happen.

Kubernetes helps with the cutting. When the controller manager runs with --allocate-node-cidrs=true and --cluster-cidr=10.244.0.0/16 (which is what kubeadm init --pod-network-cidr=10.244.0.0/16 sets), its node IPAM controller writes a slice into each Node object:

kubectl get nodes -o custom-columns=NAME:.metadata.name,PODCIDR:.spec.podCIDR
NAME           PODCIDR
controlplane   10.244.0.0/24
node01         10.244.1.0/24
node02         10.244.2.0/24

Flannel reads the node's podCIDR, writes it to /run/flannel/subnet.env, and passes it to host-local as the subnet. host-local then keeps its books as plain files, one per address in use:

ls /var/lib/cni/networks/cbr0/
10.244.1.2  10.244.1.3  10.244.1.7  last_reserved_ip.0  lock

Each file is named after an IP and contains the ID of the container that holds it. The numbers explain a familiar limit: a /24 has 254 usable addresses, the bridge takes one, and the kubelet allows 110 Pods per node by default, so a node's slice comfortably covers it. A /16 cut into /24 slices is enough for 256 nodes.

Design 2: one shared pool, as in Weave Net

Design 2: the plugin shares one pool (Weave Net)shareshareshareagreeagreeallocatesWeave range10.32.0.0/12weave on node01owns 10.32.0.0 upweave on node02owns 10.38.0.0 upweave on node03owns 10.44.0.0 upPod on node0210.38.0.3/12
Design 2: the plugin shares one pool (Weave Net). Weave Net takes 10.32.0.0/12 for the whole cluster. Its agents on the nodes agree among themselves who owns which part, and can pass free space to a node that runs out.

Parts:

  • Weave range (10.32.0.0/12)
  • weave on node01 (owns 10.32.0.0 up)
  • weave on node02 (owns 10.38.0.0 up)
  • weave on node03 (owns 10.44.0.0 up)
  • Pod on node02 (10.38.0.3/12)

Connections:

  • Weave range to weave on node01: share
  • Weave range to weave on node02: share
  • Weave range to weave on node03: share
  • weave on node01 and weave on node02: agree
  • weave on node02 and weave on node03: agree
  • weave on node02 to Pod on node02: allocates

Weave Net does not use node slices from Kubernetes. Each node runs a weave agent (a DaemonSet Pod), and the agents manage a single range together:

  • The default range is 10.32.0.0/12. That is every address from 10.32.0.0 to 10.47.255.255: 1,048,576 addresses.
  • When the cluster forms, the agents divide the range among themselves. With three nodes each owns roughly a third, about 350,000 addresses.
  • An agent allocates addresses for the Pods on its node from the part it owns. If it runs low, it asks another agent to hand over some free space. When a node is removed, its part can be reclaimed.
  • Every node has a bridge named weave with an address from the range. It is the gateway of the Pods on that node.

Weave's configuration file shows the design by what is absent:

cat /etc/cni/net.d/10-weave.conflist
{
  "cniVersion": "0.3.0",
  "name": "weave",
  "plugins": [
    { "name": "weave", "type": "weave-net", "hairpinMode": true },
    { "type": "portmap", "capabilities": { "portMappings": true }, "snat": true }
  ]
}

There is no ipam section with a subnet. The weave-net binary asks the local agent for an address. The range is a setting of the agent, changed with the environment variable IPALLOC_RANGE in the DaemonSet.

The same idea in today's plugins

PluginDesignWhere the range is keptHow to see it
FlannelSlice per node (host-local)Node spec.podCIDR, ConfigMap kube-flannel-cfgkubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}'
CalicoShared pool, handed out in blocks of 64 addresses (/26) per nodeIPPool resourceskubectl get ippools -o yaml
CiliumPool per cluster, a slice per node kept by the operatorCiliumNode resourceskubectl get ciliumnodes -o yaml
Weave NetShared pool split between agentsAgent setting IPALLOC_RANGELogs of the weave container

Three ranges that must not overlap

A cluster has three kinds of addresses: node addresses (your real network), Pod addresses (this lesson) and Service addresses (the next lesson). If two of the ranges overlap, a packet for a Pod may be sent to a Service rule or out to the physical network. Weave's default 10.32.0.0/12 sits right next to kubeadm's default Service range 10.96.0.0/12, and they do not overlap. A node network of 10.40.0.0/16, however, would sit inside Weave's range and break things.

Under the hood · Details worth knowing
  • Reading a /12. The first 12 bits are fixed. 10.32 is 00001010.0010 followed by 20 free bits, so the second number runs from 32 to 47. Exam questions sometimes ask "which of these addresses is in the Pod range?".
  • The gateway. With a bridge-based plugin the Pod's default gateway is the bridge on its node (cni0, weave). With Calico the route points at the link-local address 169.254.1.1, which the node answers for.
  • Running out. When a node's slice is full, new Pods stay in ContainerCreating with failed to allocate for range 0: no IP addresses available in range set. A common cause is not real load but leaked address files in /var/lib/cni/networks/<name>/ after a crash of the runtime.
  • Changing the cluster range later is hard. Node slices are written once. Plan the size at kubeadm init.
  • Dual stack. A cluster can have an IPv4 and an IPv6 Pod range. Nodes then show spec.podCIDRs with two entries, and Pods status.podIPs with two.

Using it

Example · Find the Pod range in any cluster

Task: "What is the range of IP addresses configured for Pods on this cluster?"

Work from the generic sources to the plugin. First the nodes and the controller manager:

kubectl get nodes -o custom-columns=NAME:.metadata.name,PODCIDR:.spec.podCIDR
kubectl -n kube-system get pod -l component=kube-controller-manager -o yaml | grep -E 'cluster-cidr|allocate-node'
NAME           PODCIDR
controlplane   10.244.0.0/24
node01         10.244.1.0/24
    - --allocate-node-cidrs=true
    - --cluster-cidr=10.244.0.0/16

On a kubeadm cluster the same value is recorded as podSubnet:

kubectl -n kube-system get cm kubeadm-config -o yaml | grep -i subnet
      podSubnet: 10.244.0.0/16
      serviceSubnet: 10.96.0.0/12

If the columns are <none> or the Pods' real addresses do not fit, the plugin keeps its own pool. Ask it: for Calico kubectl get ippools -o jsonpath='{.items[*].spec.cidr}', for Weave Net the agent's logs (next example). Always confirm with reality:

kubectl get pods -A -o wide

Example · Explore the IPAM of a Weave Net cluster

The classic lab questions, answered in order.

Which plugin, and how many agents?

ls /etc/cni/net.d/
kubectl -n kube-system get pods -l name=weave-net -o wide
10-weave.conflist
NAME              READY   STATUS    RESTARTS   AGE   IP             NODE
weave-net-4p7dx   2/2     Running   0          40m   192.168.1.10   controlplane
weave-net-mknr5   2/2     Running   0          39m   192.168.1.11   node01

One agent per node, and its IP is the node's IP because it runs on the host network.

What range does Weave use?

kubectl -n kube-system logs weave-net-mknr5 -c weave | grep ipalloc-range
INFO: 2026/11/30 09:12:44.101 Command line options: map[... ipalloc-range:10.32.0.0/12 ...]

What is the bridge on this node, and its address?

ip addr show weave
5: weave: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1376 qdisc noqueue state UP
    inet 10.38.0.0/12 brd 10.47.255.255 scope global weave

What is the default gateway of a Pod on node01? Start a Pod there and look at its routes:

kubectl run gw-test --image=busybox:1.37 --restart=Never \
  --overrides='{"spec":{"nodeName":"node01"}}' -- sleep 3600
kubectl exec gw-test -- ip route
default via 10.38.0.0 dev eth0
10.32.0.0/12 dev eth0 scope link  src 10.38.0.3

The gateway is the weave bridge of the node the Pod runs on, so the answer differs per node. That is why the question names a node.

Example · Pods stuck because a node ran out of addresses

kubectl describe pod api-7c9d | tail -n 3
  Warning  FailedCreatePodSandBox  8s  kubelet  Failed to create pod sandbox: ... plugin type="flannel"
  failed (add): failed to allocate for range 0: no IP addresses available in range set:
  10.244.1.1-10.244.1.254

Compare what the node thinks is in use with what really runs there:

ssh node01
ls /var/lib/cni/networks/cbr0/ | grep -c '^10\.'
crictl pods -q | wc -l
254
31

254 reserved addresses for 31 sandboxes: the files are left over from an earlier crash. The clean repair is to drain the node, stop the kubelet and the runtime, remove the stale files and start again:

kubectl drain node01 --ignore-daemonsets --delete-emptydir-data
systemctl stop kubelet containerd
rm -f /var/lib/cni/networks/cbr0/10.*
systemctl start containerd kubelet
kubectl uncordon node01

If the count had matched real Pods, the fix would be capacity instead: fewer Pods on that node, or a cluster built with bigger slices.

Tricks

Common mistakes

  • Thinking the API server assigns Pod IPs. It assigns Service IPs. Pod IPs come from the CNI plugin on the node.
  • Trusting --cluster-cidr when the plugin has its own pool. Weave Net and Calico can use a different range from the one given to kubeadm. The Pods' real addresses decide.
  • Mixing up the three ranges. --service-cluster-ip-range on the API server is for Services, --cluster-cidr on the controller manager is for Pods.
  • Looking at the wrong node. Bridge addresses, gateways and host-local files are per node.
  • Installing a plugin whose range overlaps the node network. Pods then cannot reach some real hosts, or the nodes cannot reach each other.

Recap

  • Pod addresses must be unique across the cluster, and the CNI plugin, through its IPAM part, makes sure of it.
  • ipam.type in /etc/cni/net.d names the IPAM plugin. host-local uses a per-node subnet and keeps files in /var/lib/cni/networks.
  • Design 1 gives each node a fixed slice (node.spec.podCIDR). Design 2 shares one pool between the plugin's agents.
  • Weave Net uses 10.32.0.0/12 by default, about a million addresses, split among its agents.
  • Find the range from the nodes, from --cluster-cidr, or from the plugin, and keep node, Pod and Service ranges apart.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.