Skip to content

BackendTrafficPolicy ConsistentHash (SourceIP) not working for UDPRoute #9534

Closed

Description

@hhllxx1121

Description:

When we change the load balancing policy in BackendTrafficPolicy to consistent hashing based on source IP (ConsistentHash + SourceIP), we notice that if it targets a UDPRoute, the traffic is not routed consistently by the source IP; instead, it still feels like it is being distributed randomly.

I wanted to check if this is a known limitation of the current Gateway API or our specific controller regarding the UDP protocol. Has anyone else run into a similar issue with UDP session persistence failing?

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
  creationTimestamp: "2026-07-20T14:37:19Z"
  generation: 3
  name: udp-policy
  namespace: test
  resourceVersion: "73853849"
  uid: 3005640b-8be2-4204-b128-a1ea74c38ade
spec:
  loadBalancer:
    consistentHash:
      tableSize: 65537
      type: SourceIP
    type: ConsistentHash
  targetRefs:
  - group: gateway.networking.k8s.io
    kind: UDPRoute
    name: route-udp-10000
status:
  ancestors:
  - ancestorRef:
      group: gateway.networking.k8s.io
      kind: Gateway
      name: test-1
      namespace: test
      sectionName: listener-udp-10000
    conditions:
    - lastTransitionTime: "2026-07-20T16:40:32Z"
      message: Policy has been accepted.
      observedGeneration: 3
      reason: Accepted
      status: "True"
      type: Accepted
    controllerName: gateway.envoyproxy.io/gatewayclass-controller
Image

Activity

  1. hhllxx1121 commented on Jul 21, 2026

    @hhllxx1121
    Author

    I gave this a try using an EnvoyPatchPolicy to inject hash_policies directly into the UDP Listener filter:

    apiVersion: gateway.envoyproxy.io/v1alpha1
    kind: EnvoyPatchPolicy
    metadata:
      name: udp-hash-policy-patch
      namespace: test
    spec:
      targetRef:
        group: gateway.networking.k8s.io
        kind: Gateway
        name: test-1
      type: JSONPatch
      jsonPatches:
        - type: "type.googleapis.com/envoy.config.listener.v3.Listener"
          name: "test/test-1/listener-udp-10000"   
          operation:
            op: add
            path: "/listener_filters/0/typed_config/hash_policies"
            value:
              - source_ip: true

    After applying this patch, the UDP traffic started being routed consistently based on the client's source IP.

    However, I am not completely sure if this is the recommended or standard way to handle this, or if BackendTrafficPolicy should automatically generate this Envoy configuration when applied to a UDPRoute. Could anyone confirm if this approach is correct or if there are any edge cases I should be aware of?

  2. added
    kind/bug
    help wanted
    and removed on Jul 27, 2026
  3. added this to the v1.9.0 Release milestone on Jul 27, 2026
  4. arkodg commented on Jul 27, 2026

    @arkodg
    Contributor

    looks like a bug, thanks for sharing the workaround until its fixed

  5. Aditya7880900936 commented on Jul 27, 2026

    @Aditya7880900936
    Contributor

    Hi @arkodg, I'd be happy to take this up if no one is already working on it.

    From the investigation and the workaround shared above, it seems BackendTrafficPolicy is correctly configuring consistent hashing for HTTP/TCP, but the equivalent Envoy configuration isn't being propagated for UDPRoute. I'll dig into how the translation for UDP listeners is generated and work on making BackendTrafficPolicy automatically configure source-IP consistent hashing for UDP instead of requiring an EnvoyPatchPolicy.

    Could you please assign this issue to me? Thanks!

  6. self-assigned this
    on Aug 23, 2026
  7. modified the milestones: v1.9.0 Release, Backlog on Aug 23, 2026
  8. removed
    help wanted
    on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions