@@ -684,39 +684,57 @@ pool.
684
684
685
685
The ` spec.trafficDistribution ` field within a Kubernetes Service allows you to
686
686
express preferences for how traffic should be routed to Service endpoints.
687
- Implementations like kube-proxy use the ` spec.trafficDistribution ` field as a
688
- guideline. The behavior associated with a given preference may subtly differ
689
- between implementations.
690
687
691
- ` PreferClose ` with kube-proxy
692
- : For kube-proxy, this means prioritizing sending traffic to endpoints within
693
- the same zone as the client. The EndpointSlice controller updates
694
- EndpointSlices with ` hints ` to communicate this preference, which kube-proxy
695
- then uses for routing decisions. If a client's zone does not have any
696
- available endpoints, traffic will be routed cluster-wide for that client.
697
-
698
- In the absence of any value for ` trafficDistribution ` , the default routing
699
- strategy for kube-proxy is to distribute traffic to any endpoint in the cluster.
688
+ ` PreferClose `
689
+ : This prioritizes sending traffic to endpoints in the same zone as the client.
690
+ The EndpointSlice controller updates EndpointSlices with ` hints ` to
691
+ communicate this preference, which kube-proxy then uses for routing decisions.
692
+ If a client's zone does not have any available endpoints, traffic will be
693
+ routed cluster-wide for that client.
694
+
695
+ {{< feature-state feature_gate_name="PreferSameTrafficDistribution" >}}
696
+
697
+ Two additional values are available when the ` PreferSameTrafficDistribution `
698
+ [ feature gate] ( /docs/reference/command-line-tools-reference/feature-gates/ ) is
699
+ enabled:
700
+
701
+ ` PreferSameZone `
702
+ : This means the same thing as ` PreferClose ` , but is more explicit. (Originally,
703
+ the intention was that ` PreferClose ` might later include functionality other
704
+ than just "prefer same zone", but this is no longer planned. In the future,
705
+ ` PreferSameZone ` will be the recommended value to use for this functionality,
706
+ and ` PreferClose ` will be considered a deprecated alias for it.)
707
+
708
+ ` PreferSameNode `
709
+ : This prioritizes sending traffic to endpoints on the same node as the client.
710
+ As with ` PreferClose ` /` PreferSameZone ` , the EndpointSlice controller updates
711
+ EndpointSlices with ` hints ` indicating that a slice should be used for a
712
+ particular node. If a client's node does not have any available endpoints,
713
+ then the service proxy will fall back to "same zone" behavior, or cluster-wide
714
+ if there are no same-zone endpoints either.
715
+
716
+ In the absence of any value for ` trafficDistribution ` , the default strategy is
717
+ to distribute traffic evenly to all endpoints in the cluster.
700
718
701
719
### Comparison with ` service.kubernetes.io/topology-mode: Auto `
702
720
703
- The ` trafficDistribution ` field with ` PreferClose ` and the
704
- ` service.kubernetes.io/topology-mode: Auto ` annotation both aim to prioritize
705
- same-zone traffic. However, there are key differences in their approaches:
721
+ The ` trafficDistribution ` field with ` PreferClose ` /` PreferSameZone ` , and the older "Topology-Aware
722
+ Routing" feature using the ` service.kubernetes.io/topology-mode: Auto `
723
+ annotation both aim to prioritize same-zone traffic. However, there is a key
724
+ difference in their approaches:
706
725
707
- * ` service.kubernetes.io/topology-mode: Auto ` : Attempts to distribute traffic
726
+ * ` service.kubernetes.io/topology-mode: Auto ` attempts to distribute traffic
708
727
proportionally across zones based on allocatable CPU resources. This heuristic
709
728
includes safeguards (such as the [ fallback
710
729
behavior] ( /docs/concepts/services-networking/topology-aware-routing/#three-or-more-endpoints-per-zone )
711
- for small numbers of endpoints) and could lead to the feature being disabled
712
- in certain scenarios for load-balancing reasons. This approach sacrifices some
713
- predictability in favor of potential load balancing.
714
-
715
- * ` trafficDistribution: PreferClose ` : This approach aims to be slightly simpler
716
- and more predictable: "If there are endpoints in the zone, they will receive
717
- all traffic for that zone, if there are no endpoints in a zone, the traffic
718
- will be distributed to other zones". While the approach may offer more
719
- predictability, it does mean that you are in control of managing a [ potential
730
+ for small numbers of endpoints), sacrificing some predictability in favor of
731
+ potentially better load balancing.
732
+
733
+ * ` trafficDistribution: PreferClose ` aims to be simpler and more predictable:
734
+ "If there are endpoints in the zone, they will receive all traffic for that
735
+ zone, if there are no endpoints in a zone, the traffic will be distributed to
736
+ other zones". This approach offers more predictability, but it means that you
737
+ are responsible for [ avoiding endpoint
720
738
overload] ( #considerations-for-using-traffic-distribution-control ) .
721
739
722
740
If the ` service.kubernetes.io/topology-mode ` annotation is set to ` Auto ` , it
@@ -732,41 +750,38 @@ interacts with them:
732
750
733
751
* Precedence of Traffic Policies: For a given Service, if a traffic policy
734
752
(` externalTrafficPolicy ` or ` internalTrafficPolicy ` ) is set to ` Local ` , it
735
- takes precedence over ` trafficDistribution: PreferClose ` for the corresponding
753
+ takes precedence over ` trafficDistribution ` for the corresponding
736
754
traffic type (external or internal, respectively).
737
755
738
756
* ` trafficDistribution ` Influence: For a given Service, if a traffic policy
739
757
(` externalTrafficPolicy ` or ` internalTrafficPolicy ` ) is set to ` Cluster ` (the
740
- default), or if the fields are not set, then `trafficDistribution:
741
- PreferClose` guides the routing behavior for the corresponding traffic type
758
+ default), or if the fields are not set, then ` trafficDistribution `
759
+ guides the routing behavior for the corresponding traffic type
742
760
(external or internal, respectively). This means that an attempt will be made
743
761
to route traffic to an endpoint that is in the same zone as the client.
744
762
745
763
### Considerations for using traffic distribution control
746
764
747
- * ** Increased Probability of Overloaded Endpoints:** The ` PreferClose `
748
- heuristic will attempt to route traffic to the closest healthy endpoints
749
- instead of spreading that traffic evenly across all endpoints. If you do not
750
- have a sufficient number of endpoints within a zone, they may become
751
- overloaded. This is especially likely if incoming traffic is not
752
- proportionally distributed across zones. To mitigate this, consider the
753
- following strategies:
754
-
755
- * [ Pod Topology Spread
756
- Constraints] ( /docs/concepts/scheduling-eviction/topology-spread-constraints/ ) :
757
- Use Pod Topology Spread Constraints to distribute your pods more evenly
758
- across zones.
759
-
760
- * Zone-specific Deployments: If you expect to see skewed traffic patterns,
761
- create a separate Deployment for each zone. This approach allows the
762
- separate workloads to scale independently. There are also workload
763
- management addons available from the ecosystem, outside the Kubernetes
764
- project itself, that can help here.
765
-
766
- * ** Implementation-specific behavior:** Each dataplane implementation may handle
767
- this field slightly differently. If you're using an implementation other than
768
- kube-proxy, refer the documentation specific to that implementation to
769
- understand how this field is being handled.
765
+ A Service using ` trafficDistribution ` will attempt to route traffic to (healthy)
766
+ endpoints within the appropriate topology, even if this means that some
767
+ endpoints receive much more traffic than other endpoints. If you do not have a
768
+ sufficient number of endpoints within the same topology ("same zone", "same
769
+ node", etc.) as the clients, then endpoints may become overloaded. This is
770
+ especially likely if incoming traffic is not proportionally distributed across
771
+ the topology. To mitigate this, consider the following strategies:
772
+
773
+ * [ Pod Topology Spread
774
+ Constraints] ( /docs/concepts/scheduling-eviction/topology-spread-constraints/ ) :
775
+ Use Pod Topology Spread Constraints to distribute your pods evenly
776
+ across zones or nodes.
777
+
778
+ * Zone-specific Deployments: If you are using "same zone" traffic
779
+ distribution, but expect to see different traffic patterns in
780
+ different zones, you can create a separate Deployment for each zone.
781
+ This approach allows the separate workloads to scale independently.
782
+ There are also workload management addons available from the
783
+ ecosystem, outside the Kubernetes project itself, that can help
784
+ here.
770
785
771
786
## {{% heading "whatsnext" %}}
772
787
0 commit comments