Pod to Pod Communication in K8

Ganesh Sahu
2 min readApr 9, 2024

--

In Kubernetes, Layer 2 (L2) networking plays a crucial role in facilitating pod-to-pod communication across the cluster. Kubernetes itself is largely agnostic to the underlying network infrastructure, whether it operates at Layer 2 or Layer 3, as long as it meets certain requirements, such as unique IP addresses for pods and certain connectivity and DNS resolution criteria. However, the use of L2 in Kubernetes can impact how pods communicate, especially within the same node or across different nodes. Here’s how L2 is involved in Kubernetes pod communication:

1. Pod-to-Pod Communication on the Same Node

  • Direct L2 Communication: Pods on the same node can communicate with each other using the node’s network namespace. Since these pods are on the same physical or virtual machine, their communication can technically occur at Layer 2, with packets being forwarded based on MAC addresses within the node. This is typically managed by the container runtime and Kubernetes CNI (Container Network Interface) plugins, which set up the virtual Ethernet bridges or similar mechanisms that facilitate this L2 communication.

2. Pod-to-Pod Communication Across Nodes

  • CNI Plugins and Overlay Networks: For communication between pods on different nodes, Kubernetes relies on CNI plugins to implement the networking layer. Some CNI plugins create overlay networks that operate above the L2 layer, encapsulating L2/L3 packets within another layer of L3 packets (like VXLAN or IP-in-IP) to tunnel pod traffic across nodes. While the overlay network itself may operate at a higher layer, it relies on the underlying L2 infrastructure to route encapsulated packets between nodes.
  • Non-Overlay CNI Plugins: There are also CNI plugins that work without creating overlay networks, directly using the underlying L2/L3 network for pod communication. In such setups, the nodes’ networking infrastructure (switches, routers) must be capable of routing traffic based on IP addresses, even though the initial packet forwarding decision (to the node’s gateway) happens at L2.

3. Service Discovery and Load Balancing

  • Kubernetes Services: While services themselves operate at Layer 4 (the Transport Layer) by directing traffic to pods based on TCP/UDP ports, they rely on the underlying L2/L3 network infrastructure to route the traffic to the correct node. Once the traffic reaches the target node, it can be forwarded to the correct pod using L2 mechanisms within the node.

Importance of L2 in Kubernetes Networking

  • Network Performance: L2 networking can offer lower latency compared to L3 routing since it doesn’t involve IP address lookup and routing decisions for pod-to-pod communication within the same node.
  • Network Simplicity: In some Kubernetes deployments, especially in on-premises environments with specific performance or security requirements, L2 networking can simplify the network design by minimizing the need for IP routing configuration.

In summary, while Kubernetes itself focuses on providing a platform for deploying and managing containerized applications, the choice of networking infrastructure and how L2 is used in pod communication can significantly affect the performance, complexity, and functionality of the Kubernetes cluster. This choice is influenced by the selected CNI plugin and the underlying network architecture of the environment where Kubernetes is deployed.

--

--

Ganesh Sahu

Senior engineer at VMware.Passionate about building elegant solutions to complex problems.