Kubernetes

Smarter Traffic Routing with Kubernetes

CV

CogniVeu

Author

22nd February 20268 mins
Smarter Traffic Routing with Kubernetes

Kubernetes networking just got smarter in v1.34. With the new spec.trafficDistribution field in Services, you can now influence traffic locality without a service mesh.

What is trafficDistribution?

The spec.trafficDistribution field gives you a hint-based mechanism to control how Kubernetes routes traffic to endpoints. The initial supported value is PreferClose, which tells kube-proxy and compatible implementations to prefer endpoints topologically closer to the client.

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - port: 80
    targetPort: 8080
  trafficDistribution: PreferClose

How PreferClose Works

When PreferClose is set:

  1. Same zone first — kube-proxy prioritises endpoints in the same availability zone as the client pod
  2. Same region fallback — if no same-zone endpoints are available, traffic goes to the same region
  3. Any endpoint last resort — if neither of the above apply, any healthy endpoint is used

This is implemented through EndpointSlice hints that each node's kube-proxy reads when making forwarding decisions.

Why This Matters

Before trafficDistribution, achieving topology-aware routing required either:

  • A service mesh (Istio, Linkerd)
  • The older topologyKeys field (now deprecated)
  • External traffic policy tricks with NodePort services

Now you get basic locality preference with a single field — no sidecar injection, no mesh control plane overhead.

Comparison: trafficDistribution vs Topology Aware Routing

FeaturetrafficDistributionTopology Aware Routing
ConfigurationSingle field on ServiceAnnotation on Service
GranularityHint-basedHint-based
Custom weightsNoNo
StabilityStable (v1.34)Beta

When to Use It

Use trafficDistribution: PreferClose when:

  • You have a multi-zone cluster and want to reduce cross-zone data transfer costs
  • Latency between zones matters for your application
  • You don't need the full complexity of a service mesh

Don't rely on it as a strict guarantee — it's a hint, not a hard rule. For hard traffic shaping (canary deployments, weighted routing, circuit breaking), you still need a service mesh or gateway-level solution.

Enabling It

The field is enabled by default from Kubernetes v1.34. For earlier versions, enable the ServiceTrafficDistribution feature gate:

# On kube-apiserver and kube-proxy
--feature-gates=ServiceTrafficDistribution=true

Checking Endpoint Hints

You can inspect the hints kube-proxy is using by looking at EndpointSlices:

kubectl get endpointslices -l kubernetes.io/service-name=my-service -o yaml

Look for the hints field under each endpoint — it will show the zones that endpoint is hinted for.

Summary

spec.trafficDistribution is a lightweight, mesh-free way to reduce cross-zone latency and egress costs in Kubernetes. For the majority of services that just need locality preference without complex traffic policies, it removes the need to adopt a full service mesh. For advanced use cases — canaries, retries, circuit breaking, mTLS — a service mesh remains the right tool.

Share this article

Related Articles

More in Kubernetes

Kubernetes Cost Optimisation: Reduce Cloud Bills by 40%

Practical strategies CogniVeu uses to cut Kubernetes cluster costs — from right-sizing workloads and Spot instances to Karpenter autoscaling and namespace-level chargeback.

CV
CogniVeu
15th March 2026

Certified Kubernetes Security

A Comprehensive Resource for Certified Kubernetes Security Specialist Candidates The Certified Kubernetes Security Specialist (CKS) examination stands as one of the most challenging certifications in

CV
CogniVeu
8th January 2026

Want to Stay Updated?

Subscribe to our newsletter and get the latest insights, case studies, and tech updates delivered straight to your inbox.