Path-Based Routing
One of the key advantages of Gateway API is the ability to route traffic from a single Gateway to multiple backend services across different namespaces. In this section, we'll add a second HTTPRoute that directs /catalog requests to the Catalog API while the existing UI route continues to serve all other traffic.
Current state
At this point we have a single HTTPRoute (ui-route) in the ui namespace that routes all traffic with path prefix / to the UI service:
NAME HOSTNAMES AGE
ui-route 5m
All requests to the Gateway ALB currently reach the UI application regardless of path.
Add the Catalog HTTPRoute
We'll create a new HTTPRoute in the catalog namespace that routes requests with path prefix /catalog to the Catalog service:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: catalog-route
namespace: catalog
spec:
parentRefs:
- name: retail-store-gateway
namespace: ui
rules:
- matches:
- path:
type: PathPrefix
value: /catalog
backendRefs:
- name: catalog
port: 80
Key points:
- The HTTPRoute is created in the
catalognamespace, alongside the service it routes to - The
parentRefsfield references the Gatewayretail-store-gatewayin theuinamespace — this is cross-namespace routing - The rule matches requests with path prefix
/catalogand forwards them to thecatalogservice on port 80
Apply the Catalog HTTPRoute:
Configure the Catalog health check
The catalog service exposes its health endpoint at /health rather than the default root path /. We need a TargetGroupConfiguration to tell the ALB where to check health:
apiVersion: gateway.k8s.aws/v1beta1
kind: TargetGroupConfiguration
metadata:
name: catalog-tgconfig
namespace: catalog
spec:
targetReference:
name: catalog
kind: Service
defaultConfiguration:
healthCheckConfig:
healthCheckPath: /health
targetReference identifies the catalog Service
healthCheckPath: /health tells the ALB to check /health instead of /
Apply the TargetGroupConfiguration:
Verify both routes
Confirm that both HTTPRoutes are now attached to the Gateway:
NAMESPACE NAME HOSTNAMES AGE
ui ui-route 5m
catalog catalog-route 30s
Test that the /catalog path returns Catalog API JSON:
You'll receive a JSON response from the Catalog service containing product data.
Verify that the root path / still returns the UI:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 19973
Connection: keep-alive
Content-Language: en-US
The Content-Type: text/html response confirms the UI service is responding on /, while the Catalog API is now accessible on /catalog — both served through the same Gateway ALB.
Cross-namespace routing
This pattern demonstrates one of Gateway API's key advantages over traditional Ingress. With Ingress, routing rules and the load balancer configuration are tightly coupled in a single resource, and sharing an ALB across namespaces requires workarounds like the IngressGroup annotation.
With Gateway API, the architecture is role-oriented:
- Cluster operators manage the Gateway (load balancer infrastructure) in one namespace
- Application teams create HTTPRoutes in their own namespaces, referencing the shared Gateway via
parentRefs
The Catalog team can independently manage their routing rules in the catalog namespace without needing access to the ui namespace where the Gateway lives. The Gateway controller handles the attachment automatically, provided the Gateway allows it through its listener configuration.
This separation of concerns makes Gateway API a natural fit for multi-team clusters where different teams own different services but share common infrastructure.