Skip to content

route HTTP gateway traffic via client policy - #4652

Open
GTRekter wants to merge 1 commit into
linkerd:mainfrom
GTRekter:ivanp/gateway-gwapi-res
Open

GTRekter wants to merge 1 commit into
linkerd:mainfrom
GTRekter:ivanp/gateway-gwapi-res

Conversation

@GTRekter

@GTRekter GTRekter commented Nov 11, 2026 •

Copy link
Copy Markdown

The gateway previously built its HTTP routes exclusively from the ServiceProfile, so HTTPRoutes served by the OutboundPolicies API were ignored for gatewayed traffic.

This change make the gateway's HTTP stack follow the same discovery logic as the sidecar: the ServiceProfile is used only when it provides routes or target overrides; otherwise routes are built from the client policy, including GWAPI HTTPRoutes attached to the target Service.

Local Test

To test the change locally, I’ve spun up two k3d clusters on a shared Docker network and installed Linkerd and Linkerd multicluster on both, linked in gateway mode. The client is deployed in k3d-02, and both versions of the server in k3d-01, together with an HTTPRoute (attached to the web Service) that routes traffic to v2 of the server when the request has the x-version: v2 header. The web Service is exported, so it’s mirrored into k3d-02 as web-k3d-01; the gateway in k3d-01 runs the proxy built from this branch.

flowchart LR
    subgraph net["Shared Docker network: playground (172.18.0.0/16)"]
        subgraph src["k3d cluster 02 — source (BEL enterprise-2.19.3)"]
            client["client pod (ns test)<br/>curl + injected linkerd-proxy"]
            mirror["Service web-k3d-01 (ns test)<br/>mirror of exported web"]
            sm["controller-k3d-01<br/>service mirror (Link, gateway mode)"]
        end
        subgraph tgt["k3d cluster 01 — target (BEL enterprise-2.19.3)"]
            gw["linkerd-gateway (:4143)<br/>proxy: localhost/linkerd/proxy:gwapi-dev<br/>(this branch)"]
            dest["linkerd-destination<br/>policy controller"]
            route["HTTPRoute web-route (ns test)<br/>parentRef: Service web:80"]
            web["Service web :80 (exported)<br/>podinfo 'v1 backend'"]
            webv2["Service web-v2 :80<br/>podinfo 'v2 backend'"]
        end
    end

    client -- "HTTP GET web-k3d-01.test:80" --> mirror
    mirror -- "endpoints = gateway 172.18.0.3/.4:4143<br/>mTLS + transport header<br/>dst = web.test.svc.cluster.local:80" --> gw
    sm -. "mirrors exported Services<br/>probes gateway :4191" .-> gw
    dest -. "OutboundPolicies(web.test:80)<br/>serves HTTPRoute web-route" .-> gw
    route -. "attached to" .-> web
    gw -- "default rule" --> web
    gw -- "header x-version: v2" --> webv2
Loading

If we send a request

$ kubectl get httproute --context k3d-01 -n test web-route -o yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: web-route
  namespace: test
spec:
  parentRefs:
  - group: core
    kind: Service
    name: web
    port: 80
  rules:
  - backendRefs:
    - group: ""
      kind: Service
      name: web-v2
      port: 80
      weight: 1
    matches:
    - headers:
      - name: x-version
        type: Exact
        value: v2
      path:
        type: PathPrefix
        value: /
  - backendRefs:
    - group: ""
      kind: Service
      name: web
      port: 80
      weight: 1
    matches:
    - path:
        type: PathPrefix
        value: /

kubectl --context k3d-02 -n test exec client -c client -- curl -s http://web-k3d-01.test.svc.cluster.local/
{
  "hostname": "web-7db88f6f5b-d7qw7",
  "message": "v1 backend",
  ...
}                                                                                                                                                                                    

$ kubectl --context k3d-02 -n test exec client -c client -- curl -s -H 'x-version: v2' http://web-k3d-01.test.svc.cluster.local/
{
  "hostname": "web-v2-5c9dd49878-tj9h7",
  "message": "v2 backend",
  ...
}

If we check the gateway logs, we are going to see a similar output as the ordinary proxy.

$ kubectl --context k3d-01 -n linkerd-multicluster logs deploy/linkerd-gateway -c linkerd-proxy --tail=5000 | grep 'Using ClientPolicy routes'
...
[   357.219685s] DEBUG ThreadId(01) inbound:accept{client.addr=10.23.1.1:15550 server.addr=10.23.1.30:4143}:server{port=4143}:direct:gateway{dst=web.test.svc.cluster.local:80}:http: linkerd_app_gateway::http: Using ClientPolicy routes
[   375.029178s] DEBUG ThreadId(01) inbound:accept{client.addr=10.23.1.1:30969 server.addr=10.23.1.30:4143}:server{port=4143}:direct:gateway{dst=web.test.svc.cluster.local:80}:http: linkerd_app_gateway::http: Using ClientPolicy routes

The metrics will confirm the routing:

$ linkerd --context k3d-01 diagnostics proxy-metrics -n linkerd-multicluster deploy/linkerd-gateway | grep outbound_http_route_backend_requests_total
outbound_http_route_backend_requests_total{parent_group="core",parent_kind="Service",parent_namespace="test",parent_name="web",parent_port="80",parent_section_name="",route_group="gateway.networking.k8s.io",route_kind="HTTPRoute",route_namespace="test",route_name="web-route",backend_group="core",backend_kind="Service",backend_namespace="test",backend_name="web",backend_port="80",backend_section_name=""} 3
outbound_http_route_backend_requests_total{parent_group="core",parent_kind="Service",parent_namespace="test",parent_name="web",parent_port="80",parent_section_name="",route_group="gateway.networking.k8s.io",route_kind="HTTPRoute",route_namespace="test",route_name="web-route",backend_group="core",backend_kind="Service",backend_namespace="test",backend_name="web-v2",backend_port="80",backend_section_name=""} 4

@GTRekter
GTRekter requested a review from a team as a code owner November 11, 2026 13:00
Signed-off-by: Ivan Porta <porta.ivan@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants