Skip to content

Commit 3e00afa

Browse files
authored
KEP-3015 PreferSameNode TrafficDistribution 1.33 (#49943)
* Update TrafficDistribution docs for 1.33 * Update TrafficDistribution/TopologyAwareHints docs for GA * Update for PreferSameTrafficDistribution
1 parent ce16fbd commit 3e00afa

File tree

5 files changed

+106
-62
lines changed

5 files changed

+106
-62
lines changed

content/en/docs/concepts/services-networking/service.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -983,20 +983,25 @@ The `.spec.trafficDistribution` field provides another way to influence traffic
983983
routing within a Kubernetes Service. While traffic policies focus on strict
984984
semantic guarantees, traffic distribution allows you to express _preferences_
985985
(such as routing to topologically closer endpoints). This can help optimize for
986-
performance, cost, or reliability. This optional field can be used if you have
987-
enabled the `ServiceTrafficDistribution` [feature
988-
gate](/docs/reference/command-line-tools-reference/feature-gates/) for your
989-
cluster and all of its nodes. In Kubernetes {{< skew currentVersion >}}, the
986+
performance, cost, or reliability. In Kubernetes {{< skew currentVersion >}}, the
990987
following field value is supported:
991988

992989
`PreferClose`
993-
: Indicates a preference for routing traffic to endpoints that are topologically
994-
proximate to the client. The interpretation of "topologically proximate" may
995-
vary across implementations and could encompass endpoints within the same
996-
node, rack, zone, or even region. Setting this value gives implementations
997-
permission to make different tradeoffs, e.g. optimizing for proximity rather
998-
than equal distribution of load. Users should not set this value if such
999-
tradeoffs are not acceptable.
990+
: Indicates a preference for routing traffic to endpoints that are in the same
991+
zone as the client.
992+
993+
{{< feature-state feature_gate_name="PreferSameTrafficDistribution" >}}
994+
995+
Two additional values are available when the `PreferSameTrafficDistribution`
996+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is
997+
enabled:
998+
999+
`PreferSameZone`
1000+
: This is an alias for `PreferClose` that is clearer about the intended semantics.
1001+
1002+
`PreferSameNode`
1003+
: Indicates a preference for routing traffic to endpoints that are on the same
1004+
node as the client.
10001005

10011006
If the field is not set, the implementation will apply its default routing strategy.
10021007

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: PreferSameTrafficDistribution
3+
content_type: feature_gate
4+
5+
_build:
6+
list: never
7+
render: false
8+
9+
stages:
10+
- stage: alpha
11+
defaultValue: false
12+
fromVersion: "1.33"
13+
---
14+
Allows usage of the values `PreferSameZone` and `PreferSameNode` in
15+
the Service [`trafficDistribution`](/docs/reference/networking/virtual-ips/#traffic-distribution)
16+
field.

content/en/docs/reference/command-line-tools-reference/feature-gates/ServiceTrafficDistribution.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ stages:
1414
- stage: beta
1515
defaultValue: true
1616
fromVersion: "1.31"
17+
toVersion: "1.32"
18+
- stage: stable
19+
defaultValue: true
20+
fromVersion: "1.33"
1721
---
1822
Allows usage of the optional `spec.trafficDistribution` field in Services. The
1923
field offers a way to express preferences for how traffic is distributed to

content/en/docs/reference/command-line-tools-reference/feature-gates/TopologyAwareHints.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ stages:
1717
- stage: beta
1818
defaultValue: true
1919
fromVersion: "1.24"
20+
toVersion: "1.32"
21+
- stage: stable
22+
defaultValue: true
23+
fromVersion: "1.33"
2024
---
2125
Enables topology aware routing based on topology hints
2226
in EndpointSlices. See [Topology Aware

content/en/docs/reference/networking/virtual-ips.md

Lines changed: 66 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -684,39 +684,57 @@ pool.
684684

685685
The `spec.trafficDistribution` field within a Kubernetes Service allows you to
686686
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.
690687

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.
700718

701719
### Comparison with `service.kubernetes.io/topology-mode: Auto`
702720

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:
706725

707-
* `service.kubernetes.io/topology-mode: Auto`: Attempts to distribute traffic
726+
* `service.kubernetes.io/topology-mode: Auto` attempts to distribute traffic
708727
proportionally across zones based on allocatable CPU resources. This heuristic
709728
includes safeguards (such as the [fallback
710729
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
720738
overload](#considerations-for-using-traffic-distribution-control).
721739

722740
If the `service.kubernetes.io/topology-mode` annotation is set to `Auto`, it
@@ -732,41 +750,38 @@ interacts with them:
732750

733751
* Precedence of Traffic Policies: For a given Service, if a traffic policy
734752
(`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
736754
traffic type (external or internal, respectively).
737755

738756
* `trafficDistribution` Influence: For a given Service, if a traffic policy
739757
(`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
742760
(external or internal, respectively). This means that an attempt will be made
743761
to route traffic to an endpoint that is in the same zone as the client.
744762

745763
### Considerations for using traffic distribution control
746764

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.
770785

771786
## {{% heading "whatsnext" %}}
772787

0 commit comments

Comments
 (0)