How Kubernetes Pushed iptables to Its Limits and Sparked ipset in the Linux Kernel

How Kubernetes' scaling demands strained iptables performance, leading to the adoption of ipset as a Linux kernel feature for efficient IP address management.

Kubernetes is a powerhouse for orchestrating containerized workloads, but its rise exposed the limits of iptables, the Linux kernel’s go-to tool for packet filtering and network address translation (NAT). As Kubernetes clusters grew, iptables struggled to keep up, paving the way for ipset to emerge as a kernel feature to address these performance bottlenecks.

The Kubernetes Challenge

Kubernetes relies heavily on networking to manage container communication across pods and nodes. It uses mechanisms like services, network policies, and load balancing, which translate into complex iptables rules for routing and filtering traffic. Each pod, service, or policy can generate multiple rules, and in large clusters, this leads to thousands—or even tens of thousands—of routing rules.

Its funny that in early Kubernetes versions Iptables usually had a very simple role to play. Direct traffic to Services to the kube-proxy. But this approach was heavily restrained by doing the routing work in userspace. Therefore the workload was shifted to Iptables.

Iptables processes rules sequentially, evaluating each packet against every rule until a match is found. As clusters scaled, the sheer volume of rules caused significant performance degradation. Packet processing slowed, latency spiked, and CPU usage soared, especially in dynamic environments where pods and services frequently churned, forcing constant rule updates.

Iptables Under Pressure

The root issue lies in iptables’ linear rule evaluation. For example, a cluster with 1,000 pods might require thousands of rules to handle NAT for service discovery or enforce network policies. Each packet must traverse this rule chain, leading to O(n) complexity. In high-traffic scenarios, this inefficiency becomes a bottleneck, impacting application performance and cluster reliability.

Kubernetes’ network policies, which define how pods communicate, exacerbate the problem. Each policy translates into multiple iptables rules, often matching on source and destination IP addresses. In large clusters, managing these IP-based rules becomes unwieldy, as iptables lacks a native way to efficiently group or manage large sets of IP addresses.

Enter ipset

To address these challenges, the Linux networking community turned to ipset, a framework designed to handle large collections of IP addresses, subnets, or ports efficiently. Unlike iptables, which evaluates rules one by one, ipset allows users to define sets of network entities and perform lookups with near-constant time complexity, thanks to its use of data structures like hash tables and bitmaps.

Ipset integrates with iptables, enabling rules to reference a single set instead of thousands of individual IP addresses. For example, a Kubernetes network policy restricting traffic to a group of pods can use an ipset containing their IP addresses, reducing the number of rules needed. This approach drastically cuts down on rule evaluation time and CPU overhead.

Ipset as a Kernel Feature

The performance demands of Kubernetes and other large-scale systems drove ipset’s adoption as a standard Linux kernel feature. Initially a separate tool, ipset was integrated into the netfilter framework, the same subsystem powering iptables. This integration allowed ipset to leverage kernel-level optimizations, making it a natural fit for high-performance networking tasks.

Ipset supports various set types, such as hash-based sets for IPs or MAC addresses and bitmap-based sets for ports, offering flexibility for different use cases. In Kubernetes, tools like Calico began using ipset to optimize network policy enforcement, reducing the overhead of managing large clusters.

Impact and Beyond

ipset did more than fix Kubernetes' performance problems. It set a precedent for scalable networking in the Linux kernel. By moving IP management into efficient data structures, ipset let clusters grow to thousands of nodes without hurting network performance. It also inspired further work, like the shift to eBPF. eBPF gives even more granular control over networking tasks. It led to very performant solutions like Cilium.

ipset is not a full replacement for iptables. It is a critical complement. It fixed a specific pain point. Its success shows how real-world demands, like those from Kubernetes, can drive kernel-level improvements. Those improvements benefit the broader ecosystem of Linux-based systems.