Introduction to CNI and Pod Networking
Overview of CNI and Its Role in Kubernetes
The Container Network Interface (CNI) is a specification and libraries for configuring network interfaces in Linux containers. In Kubernetes, the kubelet invokes the CNI plugin during pod creation to allocate an IP address, set up the pod’s network namespace, and configure routes that enable intra‑cluster communication. The plugin therefore determines how pod IP addresses are visible to the rest of the cluster and, optionally, to external networks.
Pod Networking Fundamentals
Each pod receives a unique IP address from a cluster‑wide CIDR (e.g., 10.244.0.0/16). Containers inside the pod share this address and can communicate via localhost. For a pod to reach another pod, the underlying network must provide a path between the two IP addresses. Three common forwarding models exist:
- Direct routing – pod prefixes are programmed into the underlying fabric (e.g., via BGP or static routes) so that packets travel natively without extra encapsulation.
- Node‑level summarization – each node advertises a single route that covers all pods hosted on that node (typically the node’s own
/32or a larger aggregate). Packets are first sent to the node, then delivered locally via an overlay or ARP. - Full encapsulation – pod‑to‑pod traffic is encapsulated (e.g., VXLAN, IP‑in‑IP, Geneve) and carried over the underlying L2/L3 network; the underlay sees only node IPs.
The choice of model influences reachability, failure isolation, and operational overhead.
Leaking Exact Pod Prefixes Upstream
Advantages of Leaking Pod Prefixes
- Optimal path selection – Routers can make forwarding decisions based on the exact pod
/32, enabling ECMP across multiple equal‑cost paths and reducing sub‑optimal hairpinning through a node. - Transparent troubleshooting – Tools like
tracerouteorpingsee the real pod IP at each hop, simplifying correlation between application logs and network traces. - Simplified security policy – Network policies that rely on source/destination IP can be enforced directly on physical routers or firewalls without needing to translate encapsulated headers.
Disadvantages of Leaking Pod Prefixes
Reachability Concerns
- Address exhaustion risk – Advertising tens or hundreds of thousands of
/32routes can exceed the FIB limits of commodity routers or switches, leading to route drops and black‑holing. - Asymmetric routing – If return paths are not symmetrically advertised (e.g., due to route filtering), packets may traverse different paths, causing out‑of‑order delivery or TCP retransmits.
- Dependency on underlay routing protocol – The model requires a dynamic routing protocol (BGP, OSPF) that is correctly configured on every leaf/spine device; misconfiguration can isolate entire subnets.
Failure Isolation Challenges
- Failure propagation – A misbehaving pod that injects bogus routes (e.g., via a compromised CNI) can pollute the underlay, affecting unrelated workloads or even the control plane.
- Blast‑radius expansion – Link or node failures that affect a subset of pods manifest as multiple individual route withdrawals, increasing churn and potentially triggering routing instability (e.g., BGP flap damping).
Debugging Complexity
- Volume of telemetry – Monitoring tools must process a high cardinality of routes, which can overwhelm dashboards and alerting systems.
- Route‑origin tracing – Determining whether a missing route is due to a pod crash, CNI misconfiguration, or underlay filter requires correlating CNI logs with router logs, increasing mean‑time‑to‑resolve (MTTR).
Summarizing Behind Node Routes
Benefits of Node Route Summarization
- Scalable FIB usage – Each node contributes at most one route (often a
/32host route or a small aggregate), keeping the underlay route table size linear with node count rather than pod count. - Failure containment – When a node loses connectivity, only its aggregate route is withdrawn, limiting the scope of routing churn.
- Simplified policy enforcement – Security devices can apply rules based on node IP ranges, reducing the number of distinct ACL entries.
Drawbacks of Node Route Summarization
Impact on Reachability
- Sub‑optimal forwarding – Traffic to a pod is first sent to the node’s IP, then delivered via an overlay or local ARP. This adds an extra hop and can prevent ECMP across multiple paths to the same node.
- Potential hairpinning – If the overlay uses the same node as both ingress and egress point (e.g., misconfigured VXLAN), packets may loop within the node.
Effects on Failure Isolation
- Overlay‑dependent failure detection – Node‑level summarization hides pod‑level failures; a crashing pod does not trigger a route change, so black‑hole detection relies on higher‑level health checks (e.g., liveness probes).
- Stale overlay state – If the overlay control plane (e.g., VXLAN FDB) fails to update, traffic may continue to be sent to a dead pod until the overlay times out.
Debugging Considerations
- Encapsulation obscurity – The underlay sees only node IPs, so
traceroutestops at the node; operators must inspect overlay tables (e.g.,bridge fdb show,ip route get <pod‑IP>) to see the next hop. - Correlation overhead – Relating application logs to network events requires mapping pod IP → node IP → overlay tunnel, adding a step to the troubleshooting workflow.
Staying Encapsulated
Advantages of Encapsulation
- Zero impact on underlay – The underlay never sees pod IPs, preserving FIB resources and allowing the use of simple L2 networks (e.g., a flat VLAN) without routing protocol configuration.
- Strong isolation – Encapsulation creates a clear trust boundary: only nodes that participate in the overlay can decapsulate and forward pod traffic, limiting the blast radius of a compromised node.
- Flexibility with overlapping IP spaces – Different clusters or namespaces can reuse the same pod CIDR because the underlay only transports encapsulated packets.
Disadvantages of Encapsulation
Reachability Limitations
- Maximum transmission unit (MTU) overhead – Encapsulation adds headers (e.g., 50 bytes for VXLAN), reducing the effective payload MTU and potentially causing fragmentation or TCP MSS clamping.
- Latency penalty – Each packet incurs extra processing (encapsulation/decap) and possibly an extra hop through a tunnel endpoint, which can affect latency‑sensitive workloads.
Failure Isolation Benefits
- Containment of misbehaving pods – A pod that sends malformed encapsulated packets cannot affect the underlay; the worst case is local CPU overhead on the node.
- Control‑plane separation – Overlay failures (e.g., VXLAN port misconfiguration) are isolated to the nodes involved, leaving the rest of the cluster reachable via the underlay.
Debugging Tradeoffs
- Limited visibility – Standard L3 tools cannot see inside the tunnel; operators must rely on CNI‑specific diagnostics (e.g.,
cilium monitor,calicoctl node status,flannel-dashboard). - Encapsulation‑specific failure modes – Issues such as VXLAN VNI mismatches, UDP port collisions, or hardware offload incompatibilities require specialized knowledge and tooling.
Troubleshooting CNI Configuration Issues
Identifying Common Configuration Mistakes
- Incorrect MTU – Forgetting to lower the MTU on pod interfaces or host veth pairs when using encapsulation leads to packet loss.
- Missing or duplicate IPAM ranges – Overlapping pod CIDRs across nodes cause IP conflicts and intermittent connectivity.
- BGP peer misconfiguration – Wrong AS numbers, missing passwords, or incorrect
peerIPprevent route advertisement or summarization. - Encapsulation mode mismatch – One node configured for VXLAN while another uses IP‑in‑IP results in black‑hole traffic because packets cannot be decapsulated.
Using CLI Tools for Debugging
Example: Using kubectl for Troubleshooting
# List pods with their IPs and node assignment
kubectl get pods -o wide
# Describe a pod to see events (e.g., CNI timeout)
kubectl describe pod <pod-name> -n <namespace>
# Get the CNI config used on a node
kubectl get node <node-name> -o jsonpath='{.metadata.annotations.cni\\.projectcalico\\.org/ipv4pools}'
Example: Using ip Command for Network Inspection
# Show routes installed by the CNI on a node
ip route show table main | grep -E '10\.244\.|flannel\.|calico'
# Inspect VXLAN device (if encapsulation used)
ip -d link show vxlan.calico
# Display FDB entries for a VXLAN device (shows which pod MAC is reachable via which remote VTEP)
bridge fdb show dev vxlan.calico
# Check BGP session state (if using FRR or bird)
vtysh -c "show ip bgp summary"
These commands help distinguish whether a connectivity problem stems from missing underlay routes, encapsulation failures, or IPAM conflicts.
Code Examples for CNI Configuration
Leaking Pod Prefixes Example
YAML Configuration Snippet (Calico BGP Advertising Pod /32s)
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
name: default-ippool
spec:
cidr: 10.244.0.0/16
ipipMode: Never # Disable encapsulation
natOutgoing: false # Do not SNAT pod traffic
nodeSelector: all() # Apply to all nodes
bgp:
advertise: true # Advertise each pod IP as a /32
advertiseClusterIPs: false # Do not advertise Service cluster IPs
CLI Command for Applying Configuration
kubectl apply -f calico-bgp-pod-prefixes.yaml
Assumption: A BGP speaker (e.g., Calico’s bird or external FRR) is running on each node and peered with the fabric.
Node Route Summarization Example
YAML Configuration Snippet (Flannel host‑gw mode)
# flannel-config ConfigMap (applied via kube-flannel.yml)
kind: ConfigMap
apiVersion: v1
metadata:
name: kube-flannel-cfg
namespace: kube-system
data:
cni.conf: |
{
"name": "cbr0",
"type": "flannel",
"delegate": {
"isDefaultGateway": true
}
}
net-conf.json: |
{
"Network": "10.244.0.0/16",
"Backend": {
"Type": "host-gw"
}
}
CLI Command for Applying Configuration
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
Assumption: The underlying network allows L2 connectivity between nodes so that each node can install a route for the pod CIDR via the neighbor’s IP (host‑gw).
Encapsulation Example
YAML Configuration Snippet (Calico IP‑in‑IP)
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
name: ipip-pool
spec:
cidr: 10.244.0.0/16
ipipMode: Always # Encapsulate with IP‑in‑IP
natOutgoing: true
nodeSelector: all()
vxlanMode: Never
CLI Command for Applying Configuration
kubectl apply -f calico-ipip.yaml
Assumption: The underlying network permits IP protocol 4 (IP‑in‑IP) between nodes; firewalls must not drop it.
Scaling Limitations and Considerations
Scalability Tradeoffs for Each Approach
Leaking Pod Prefixes Scalability
- Route table growth: O(P) where P = number of pods. In a 5 000‑node cluster with 110 pods/node → ~550 k
/32routes. Many hardware switches support ~1 M FIB entries, but TCAM used for ACLs may become a bottleneck. - Churn rate: Pod turnover generates frequent route updates; at high churn (e.g., burst autoscaling) the BGP update rate can exceed the hold‑time timers, causing flaps.
- Mitigation: Route aggregation at the aggregation layer (e.g., summarizing per‑rack) or using a hierarchical BGP design (leaf‑spine with route‑reflectors).
Node Route Summarization Scalability
- Route table growth: O(N) where N = number of nodes. Even a 10 000‑node cluster yields only 10 k routes, well within the limits of most commodity switches.
- Churn rate: Node failures or additions generate far fewer updates than pod‑level changes, resulting in lower routing churn.
- Mitigation: Ensure the overlay control plane scales with node count; consider using a distributed overlay (e.g., VXLAN with BGP EVPN) to avoid bottlenecks.