Shaping Kubernetes Network Traffic With Topology-Aware Routing

FoxuTech
3 min readJul 13, 2024

--

In cloud-based deployments, Kubernetes clusters are often spread across multiple availability zones for redundancy and scalability. However, by default, Kubernetes services distribute traffic randomly between pods, which can lead to inefficiencies. Traffic might travel between zones unnecessarily, increasing latency and potentially incurring extra costs. In this post, let’s understand about Kubernetes traffic shaping with Topology Aware Routing.

What is Topology-Aware Routing?

Topology-aware routing (TAR) is a Kubernetes feature that optimizes network traffic flow by considering the physical or logical layout of the cluster’s infrastructure. With TAR enabled, Kubernetes can make informed routing decisions to prioritize keeping traffic within the zone it originated from. This reduces latency, improves performance, and potentially minimizes network egress costs.

How Does TAR Work?

Here’s a breakdown of the process:

  1. Pod Communication: Pods within your application communicate with each other through services. These services act as load balancers, directing traffic to the appropriate pods based on selectors and labels.
  2. Endpoint Slices: When a service is created, Kubernetes creates EndpointSlices, which are essentially service endpoint information divided by zone. These EndpointSlices contain details about pods that belong to the service, including their zone location.
  3. Topology Hints: The EndpointSlice controller incorporates the zone information into “topology hints.” These hints are attached to the EndpointSlices, indicating the preferred zone for the endpoints.
  4. Kube-proxy: Kube-proxy, a network proxy running on each node, utilizes these topology hints when selecting endpoints for service traffic. It prioritizes selecting pods within the same zone as the requesting pod whenever possible.

Benefits of Topology-Aware Routing

  • Reduced Latency: By keeping traffic local, TAR minimizes the distance packets need to travel, resulting in faster communication between pods.
  • Improved Performance: Lower latency translates to a more responsive and performant application.
  • Cost Optimization: In certain cloud environments, data transfer between zones incurs additional charges. TAR helps minimize these costs by keeping traffic within the same zone.

Example Scenario

Imagine a two-zone Kubernetes cluster (Zone A and Zone B) hosting a microservices application. Service A in Zone A frequently communicates with Service B in Zone B. Without TAR, traffic between these services might traverse zones, introducing unnecessary latency and potentially incurring extra costs.

With TAR it keeps communication local, enhancing performance and potentially reducing costs. Let’s check with some examples:

Detailed Example

Assume, you have multiple nodes running in different zones in the cloud (e.g., us-east-1a, us-east-1b), You have two applications: fox-App1 and fox-App2. Each application has multiple containers, and the containers are running in different zones.

In this fox-App1 frequently sends requests to fox-App2. How do you make sure that fox-App1 container make requests to fox-App2 container, which are situated in the same zone?

Continue Reading on https://foxutech.com/shaping-kubernetes-network-traffic-with-topology-aware-routing/

If you like our posts, don’t forget to subscribe and share with your friends.

You can subscribe us on https://www.youtube.com/@FoxuTech

Follow us on Twitter & Instagram

--

--

FoxuTech
FoxuTech

Written by FoxuTech

Discuss about #Linux, #DevOps, #Docker, #kubernetes, #HowTo’s, #cloud & IT technologies like #argocd #crossplane #azure https://foxutech.com/

No responses yet