Cloud Native 22 min read

How Does Kubernetes Really Handle Networking? A Deep Dive

This article explains the Kubernetes networking model, covering container‑to‑container, pod‑to‑pod, pod‑to‑service, and external traffic flows, and shows how Linux network namespaces, virtual Ethernet pairs, bridges, iptables, IPVS, LoadBalancers and Ingress controllers work together to route traffic inside and outside a cluster.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How Does Kubernetes Really Handle Networking? A Deep Dive

Container‑to‑Container Networking

Kubernetes runs distributed clusters, making networking a core component. In Linux each process runs in a network namespace that provides its own routing, firewall rules, and network devices, effectively giving every namespace a separate network stack.

Network namespaces can be created with the ip command, e.g.: $ ip netns add ns1 The namespace appears under /var/run/netns and can be listed with:

$ ls /var/run/netns
ns1
$ ip netns list
ns1

Docker implements a pod as a group of containers sharing a network namespace, so all containers in a pod have the same IP address and can reach each other via localhost.

The root network namespace connects to each pod’s namespace via a virtual Ethernet (veth) pair. One end of the pair is placed in the root namespace, the other in the pod’s namespace, and a Linux bridge links all veth ends together.

Pod‑to‑Pod Networking

Each pod receives a unique IP address and communicates directly with other pods. On the same node, pods are linked through veth pairs and a bridge (cbr0). The bridge learns MAC addresses via ARP and forwards frames accordingly.

When a pod sends a packet, it travels from its eth0 to the veth pair, reaches the bridge, and the bridge forwards it to the destination pod’s veth pair, ultimately arriving at the destination pod’s eth0.

Across different nodes, each node is allocated a CIDR block for its pods. Packets destined for a pod’s IP are routed to the node that owns the corresponding CIDR, then delivered via the same bridge/veth mechanism.

Pod‑to‑Service Communication

Kubernetes Service objects provide a stable virtual IP (ClusterIP) that load‑balances traffic to a set of pods. The kube‑proxy component programs iptables (or IPVS) rules so that packets sent to the Service VIP are DNAT‑ed to a selected pod IP.

netfilter and iptables

iptables uses the netfilter framework to rewrite packet headers. When a Service is created, kube‑proxy adds rules that match the Service VIP, select a backend pod, and change the destination IP to that pod’s IP. The conntrack subsystem records the mapping so that return traffic is rewritten back to the Service VIP.

IPVS

IPVS, built on netfilter, provides kernel‑level load balancing with hash tables for higher scalability. When kube‑proxy runs in IPVS mode, a virtual IPVS interface is created per Service, and IPVS servers are added for each backend pod.

External Traffic to Services

To expose services outside the cluster, two common approaches are used: LoadBalancer services and Ingress controllers.

LoadBalancer

In cloud environments (e.g., AWS), a LoadBalancer service creates a cloud load balancer that forwards traffic to node ports. iptables on each node then routes the traffic to the appropriate pod, with conntrack handling return‑path NAT.

Ingress Controller

An Ingress object provides HTTP/HTTPS routing based on URL paths. The Ingress controller creates an external load balancer (e.g., AWS ALB) that forwards traffic to node ports, where iptables again directs it to the correct pod.

Summary

The Kubernetes networking model ties together Linux network namespaces, virtual Ethernet devices, bridges, iptables/IPVS, and cloud load‑balancing components to enable container‑to‑container, pod‑to‑pod, pod‑to‑service, and external traffic flows. While the topic is broad, this overview provides a foundation for deeper exploration.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

KubernetesNetworkingServiceContainersloadbalancer
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.