Skip to main content
Hello, and welcome to this lesson. In this article we cover IP Address Management (IPAM) in Kubernetes: how Pod IPs are allocated, where allocation state is kept, and who ensures there are no duplicate IPs. This is focused on Pod/network IPs, not the node host addresses.

Scope

  • This article does not cover the IP addresses assigned to cluster nodes (those are usually managed by your cloud provider, DHCP, or other infrastructure tooling).
  • We focus on how the per-node virtual bridge networks receive subnets, how Pods obtain IPs, where that allocation state lives, and who prevents duplicates.

Who is responsible?

CNI (Container Network Interface) defines the standard: the CNI plugin (the network implementation) is responsible for assigning IPs to containers (Pods). The plugin must allocate IPs and ensure uniqueness.
CNI plugins are responsible for Pod IP allocation. Kubernetes itself does not perform the actual IP assignment — the active CNI plugin does.
An infographic about the Container Network Interface (CNI) showing plugin responsibilities. To the right is a network diagram of three nodes, each with a bridge (v-net-0) assigning pod IPs in the 10.244.x.x ranges and a shared LAN (192.168.1.0).

Typical CNI IPAM flow (simple plugin)

In a minimal CNI implementation, IP allocation happens during the ADD lifecycle. The simplified flow:
  • ADD
    • Create a veth pair on the host and move the container side into the container network namespace
    • Assign the IP address inside the container netns
    • Add any required routes (default gateway, host routes)
    • Bring interfaces up
  • DEL
    • Remove the veth and clean up the allocated IP
Example pseudocode for a simple script-style CNI plugin:

Where to store allocation state?

Kubernetes does not mandate how a plugin must store IP allocation state. The only requirement is that the plugin must not hand out duplicate IPs. Common approaches:
  • Local per-host storage (e.g., a file or a small local datastore). The plugin reads/updates this during ADD and DEL.
  • Centralized allocator (external service) which tracks all allocations and answers allocation/free requests.
  • Use a standard IPAM plugin (recommended) so you don’t need to re-implement allocation/persistence logic.
Table: Common IPAM storage patterns CNI provides standard IPAM plugins so you don’t have to implement allocation from scratch. A popular choice for local per-host allocation is the host-local IPAM plugin. Using a standard IPAM simplifies your plugin: you call the IPAM plugin to obtain a free IP, then configure the container interface with that IP. Example plugin pseudocode that delegates to host-local:

CNI configuration: the ipam section

CNI network configuration (typically under /etc/cni/net.d/) contains an ipam block. Your CNI plugin should parse this block to determine which IPAM implementation to call and what parameters (subnet, routes, ranges) to pass. Example CNI file that uses host-local IPAM:
Notes:
  • Parse the ipam.type field to decide which IPAM plugin to invoke.
  • Pass the full CNI input JSON to the IPAM plugin (so it has tenant/pod info and the same config).
  • The IPAM plugin returns an allocation result (IP + gateway + routes) in JSON; use it to configure the container.

How your plugin should use IPAM

  • Parse the CNI config to discover ipam.type and parameters.
  • If type is host-local (or another known plugin), invoke that plugin/binary with the same CNI input to obtain a free IP.
  • Configure the container namespace with the returned IP, gateway, and any routes.
  • On DEL, call the IPAM plugin to release the IP and clean up local state.
If you implement local allocation logic, be careful about concurrency and persistence. Ensure atomic allocation and durable state to avoid IP duplication after crashes or restarts.

Best practices

  • Prefer standard, well-tested IPAM plugins (like host-local) unless you have specific needs.
  • If you implement your own allocator:
    • Use locks or atomic operations for concurrent allocations.
    • Persist allocation state to survive restarts.
    • Reconcile state periodically to detect leaks.
  • Understand whether your network model requires per-host subnets (e.g., Flannel host-gw) or a cluster-wide allocator.

Quick summary table

Closing

You can either:
  • Implement IP allocation directly in your plugin (requires careful concurrency and persistence handling), or
  • Delegate allocation to a standard IPAM plugin like host-local (recommended for simplicity and reliability).
Try hands-on practice: install a CNI plugin that uses host-local IPAM and observe ADD/DEL lifecycle logs to see allocations and releases in action.

Watch Video

Practice Lab