Cross-Namespace Gateway and HTTPRoute Binding with Kubernetes Gateway API
Scenario
Your organization runs a railway platform with a strict separation between infrastructure and application teams. The infrastructure team owns the japan-railway-gateway namespace and manages all Gateway resources. The application team owns the japan-railway namespace where services run.
Two backend services are already running in the japan-railway namespace:
schedule-service— serves train schedule data on port3000ticket-service— serves ticket booking data on port5000
Your goal is to expose both services externally through a single Gateway using path-based routing under the domain japan-railway.io.
Task
Create the required Kubernetes Gateway API resources across two namespaces:
- A Gateway named
railway-gatewayin namespacejapan-railway-gatewaythat:- Listens on HTTP port
80 - Uses
gatewayClassName: nginx - Allows HTTPRoutes from the
japan-railwaynamespace viaallowedRoutes
- Listens on HTTP port
- An HTTPRoute named
railway-routesin namespacejapan-railwaythat:- Attaches to
railway-gatewayin namespacejapan-railway-gatewayviaparentRefswithnamespacefield set - Uses hostname
japan-railway.io - Routes
/schedule→schedule-serviceon port3000 - Routes
/tickets→ticket-serviceon port5000
- Attaches to
Once the Gateway gets an external IP, verify that both routes respond correctly using japan-railway.io (/etc/hosts is already pre-configured on cplane-01).
curl http://japan-railway.io/schedule | jq
curl http://japan-railway.io/tickets | jq
Gateway in japan-railway-gateway namespace routing traffic to services in japan-railway namespace.
⏳ Wait 2 minutes for MetalLB and NGINX Gateway API setup.
🚫 Do not change existing Services or Deployments.
Hint
When the Gateway and HTTPRoute are in different namespaces, two things are required. The Gateway listener must explicitly allow routes from the application namespace:
listeners:
- name: http
port: 80
protocol: HTTP
allowedRoutes:
namespaces:
from: Selector
selector:
matchLabels:
kubernetes.io/metadata.name: japan-railway
The HTTPRoute parentRefs must include the Gateway namespace:
parentRefs:
- name: railway-gateway
namespace: japan-railway-gateway