Kubernetes Network Latency: A Root-Cause Analysis Guide from CNI Overhead to eBPF
"Our service suddenly got slow, but it doesn't seem to be the application code or Pod resources. Could it be the cluster network?"
In cloud-native environments, this is a puzzle every SRE and DevOps engineer runs into at least once. Kubernetes maximizes developer productivity through abstraction, but behind that abstraction sits a complex, hard-to-predict network stack. Especially as traffic grows and extra layers such as a service mesh are added, slowness is frequently caused not by application logic but by network latency.
This article does not stop at the surface complaint that "the network is slow." It is a guide that digs into the depths of the Kubernetes cluster network stack—CNI, overlays, and kernel packet processing—to diagnose the root causes of latency and present practical optimization approaches.
Understanding the Root Causes of Kubernetes Network Latency
Pod-to-Pod communication in Kubernetes is more than simple L3 routing. When Pod A talks to Pod B, several layers of overhead are added along the way. That overhead can be the primary culprit behind latency.
The largest sources of overhead are CNI (Container Network Interface) plugins and network overlay architectures.
Comparative Analysis of Overhead by CNI Type
CNI is the core component that assigns IP addresses to Pods and provides network connectivity. Overhead characteristics differ sharply depending on which CNI you use.
| CNI Type | How It Works | Primary Overhead | Best Fit |
|---|---|---|---|
| Flannel (VXLAN) | Overlay tunneling (IP-in-IP or VXLAN) | Packet encapsulation/decapsulation overhead; possible MTU reduction | Simple test environments where fast deployment is the priority |
| Calico (BGP) | Routing-protocol based (uses the underlay) | BGP peering and policy-enforcement overhead | Environments with a well-built existing datacenter network (underlay) |
| Cilium (eBPF) | Direct packet processing at the kernel level (eBPF) | Initial learning curve; overhead minimized when applying policies | High-performance production environments with complex security policies |
Key takeaway: Overlay solutions based on Flannel or VXLAN consume CPU cycles just to encapsulate packets and increase packet size, which can trigger MTU issues. Cilium's use of eBPF, by contrast, bypasses or accelerates the kernel networking stack and dramatically reduces that overhead.
🔍 Deep Dive 1: Measuring Overlay and CNI Overhead
Finding the cause of latency requires measurement, not guesswork.
1. Confirming Overhead by Analyzing Packet Flow
tcpdump is the most basic tool for capturing network traffic and visually confirming which protocols and ports packets are using.
# 특정 인터페이스(eth0)에서 특정 포트(80)로 나가는 패킷을 캡처
sudo tcpdump -i eth0 -n port 80 -c 10If captured packet headers are longer than expected, or if unexpected tunneling headers (e.g., VXLAN) appear repeatedly, overlay overhead is a likely suspect.
2. Using Real Latency Measurement Tools
ping alone is not enough. You need to measure actual data-transfer performance.
iperf3: Ideal for measuring maximum bandwidth and average latency between two endpoints.Bash# 서버에서 실행 (리스너 모드) iperf3 -s # 클라이언트에서 실행 (지연 시간 및 대역폭 측정) iperf3 -c <서버_IP> -t 10 -P 5mtr(My Traceroute): Shows how average latency changes at every hop the packet traverses, which is useful for narrowing down a bottleneck to a specific segment.
⚙️ Deep Dive 2: Resolving Bottlenecks at the Kernel and Packet-Processing Level
Beyond overlay overhead, the problem may be kernel-level configuration. The two most common bottlenecks are MTU mismatch and the packet-processing path.
1. MTU and MSS Tuning Guide (Must-Check Items)
If MTU (Maximum Transmission Unit) shrinks because of network equipment or overlay tunneling, large packets are split into multiple smaller packets (fragmentation). That process itself introduces latency, and packet loss is more likely during reassembly.
Inspection and adjustment order:
- Check current MTU: Use the
ip acommand to check the MTU of each interface. (Typically 1500) - Account for overlay overhead: If you use VXLAN or IP-in-IP, at least 50–100 bytes of overhead is added, so lowering the actual MTU to around 1400–1450 can be more stable.
- Adjust MSS: After changing MTU, you should also adjust MSS (Maximum Segment Size), the maximum size of a TCP session.
Bash
# 예시: 커널 파라미터 조정 (재부팅 또는 sysctl -p 필요) sysctl -w net.ipv4.tcp_mtu_hook_dev=eth0 sysctl -w net.ipv4.tcp_mem = 16777216
2. The Power of eBPF-Based Visibility
Traditional network debugging could show where a packet got stuck, but it was hard to understand why.
eBPF (extended Berkeley Packet Filter) lets you run user-defined code inside the kernel, so you can intercept packets at specific points (hook points) in the network stack, log the processing path, and even control traffic. Cilium is the most well-known example of this. eBPF touches the kernel networking path directly to reduce overhead and, even when applying policies, minimizes context switches into user space to maximize performance.
💡 Practitioner experience: In environments with intermittent latency under large traffic spikes, simply swapping CNIs often does not solve the problem. After analyzing header lengths of packets captured with
tcpdump, we found that MTU shrinkage caused by overlay tunneling was the main cause. That experience taught us that "the right tuning for the current environment" matters more than "the latest technology."
🚀 Practical Tuning Strategies for Performance Improvement
Once diagnosis is done, it is time to apply fixes.
- Revisit and replace the CNI: If overlay overhead is clear, seriously consider switching to a CNI that supports BGP-based underlay networking (e.g., Calico) or adopting eBPF-based Cilium.
- Minimize network policies: Over-applying a service mesh or NetworkPolicy adds inspection overhead for every policy. Apply only the policies you truly need, and optimize the order in which they are applied.
- Optimize L4/L7 load balancers: The load-balancing algorithm of an Ingress Controller or service mesh can itself be a source of latency. Revisit whether session affinity (sticky sessions) is actually required instead of simple round-robin, and handle as much as possible at L4 (IP/port) rather than L7.
Conclusion: Designing Architecture for Latency Monitoring
Network latency is not something you measure once and forget. It is an area that demands continuous monitoring and a repeated tuning cycle.
When monitoring performance, do not look only at average latency. Always treat P95 and P99 latency as first-class metrics. High P99 latency means a tiny fraction of requests is extremely slow, and that is usually a strong signal of overhead or a kernel-level bottleneck.
I hope this guide serves as a practical compass for resolving network performance bottlenecks in your cluster.
Frequently Asked Questions (FAQ)
Q1. When measuring latency in Kubernetes, should I look at the application level or the network level first?
A1. Always suspect the network level first. Even if the application is healthy, packet loss or high latency in the network layer will make the service slow. Use iperf3 and tcpdump to check for network-based bottlenecks first.
Q2. Does using eBPF solve every network problem? A2. eBPF is transformative for performance and visibility, but it is not a silver bullet. eBPF is a tool for optimizing how packets are processed; it does not decide which protocol to use. Fundamental MTU mismatches or a poorly designed routing topology may not be solvable with eBPF.
Q3. Does using a service mesh (Istio, etc.) always increase latency? A3. Not always, but traffic complexity grows exponentially. A service mesh provides powerful features (mTLS, traffic management), but the compute overhead of the sidecar proxies those features add can become a source of latency. Always run performance tests and establish a baseline.
Nodelog는 모든 콘텐츠의 내용과 출처를 공개 전에 검토합니다. 환경(OS·버전)에 따라 결과가 달라질 수 있는 기술 정보는 공식 문서와 함께 확인하며, 검토 기준과 정정 원칙은 편집 정책에서 안내합니다. 오류를 발견하시면 이메일로 제보해 주세요 — 확인 후 신속히 정정합니다.
Comments
Be the first to comment.