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: PreferCloseHow PreferClose Works
When PreferClose is set:
- Same zone first — kube-proxy prioritises endpoints in the same availability zone as the client pod
- Same region fallback — if no same-zone endpoints are available, traffic goes to the same region
- 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
topologyKeysfield (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
| Feature | trafficDistribution | Topology Aware Routing |
|---|---|---|
| Configuration | Single field on Service | Annotation on Service |
| Granularity | Hint-based | Hint-based |
| Custom weights | No | No |
| Stability | Stable (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=trueChecking 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 yamlLook 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.
