Sub topic 17
Beyond HTTP: GRPCRoute and TLS or TCP routes
This chapter assumes you have read the earlier chapters on Gateways, listeners and HTTPRoute attachment. It covers the Gateway API route types for traffic that is not plain HTTP.
How Ingress NGINX handled it
Ingress only models HTTP and HTTPS. Ingress NGINX added the rest with extensions:
- gRPC used the annotation
nginx.ingress.kubernetes.io/backend-protocol: "GRPC"on a normal Ingress. - TCP and UDP ports were exposed through a controller-wide
tcp-servicesorudp-servicesConfigMap, outside the Ingress resource. - TLS passthrough used the
ssl-passthroughannotation, which also required a controller flag.
The Gateway API replaces these with typed routes. Each route type attaches to a listener whose protocol matches it.
GRPCRoute
GRPCRoute matches on the gRPC service and method names instead of URL paths. It is part of the standard channel as v1, so it works like HTTPRoute. It attaches to the same https listener as the HTTPRoutes from earlier chapters.
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: orders
namespace: shop
spec:
parentRefs:
- name: shared-gateway
namespace: gateway-system
sectionName: https
hostnames:
- grpc.example.com
rules:
- matches:
- method:
service: shop.orders.v1.OrderService
method: GetOrder
backendRefs:
- name: orders-v1
port: 9000
- backendRefs:
- name: orders-default
port: 9000The first rule sends one method to orders-v1. The second rule has no matches, so it catches all other calls. The Service port should use appProtocol: kubernetes.io/h2c for plaintext gRPC behind the Gateway. Some implementations need this to speak HTTP/2 to the backend.
TLS and TCP routes
For passthrough, the Gateway does not decrypt traffic. It routes on the SNI name in the TLS handshake, and the backend holds the certificate. You declare a TLS listener with mode: Passthrough, then attach a TLSRoute.
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TLSRoute
metadata:
name: db-passthrough
namespace: shop
spec:
parentRefs:
- name: shared-gateway
namespace: gateway-system
sectionName: tls-passthrough
hostnames:
- db.example.com
rules:
- backendRefs:
- name: db
port: 5432This assumes shared-gateway has a listener named tls-passthrough with protocol: TLS and tls.mode: Passthrough. TCPRoute is similar but has no hostnames, because plain TCP carries no name to match. It binds one listener port to a backend.
Gotchas
- TLSRoute and TCPRoute are
v1alpha2in the experimental channel in many releases. You must install those CRDs, and your implementation must support them. Check your version's release notes. - UDP has UDPRoute, with the same maturity caveats.
- A listener accepts only the route kinds that fit its protocol. A mismatch shows up as an
Accepted: FalseorResolvedRefs: Falsecondition on the route. - Replacing the
tcp-servicesConfigMap means opening a listener port on the Gateway. Account for the Service and firewall ports your implementation exposes.
Exercise
Why does a TCPRoute have no hostnames field, while a TLSRoute does?
Show answer
Plain TCP carries no name the Gateway can read, so the route binds to a listener port. A TLS handshake includes the SNI server name, so a TLSRoute can match on hostnames even in passthrough mode.