Sub topic 16
Beyond HTTP: GRPCRoute, TLSRoute, and TCPRoute
HTTPRoute covers most web traffic. The Gateway API also defines route kinds for gRPC and for raw TLS and TCP streams. This chapter assumes you know how an HTTPRoute attaches to a Gateway through parentRefs, how a listener's allowedRoutes limits attachment, and how backendRefs point at Services.
One pattern, several route kinds
Every route kind follows the HTTPRoute pattern. A route names a parent Gateway in parentRefs, optionally narrows the match, and lists backendRefs. The route kind differs in what the Gateway can see in the traffic, and that decides what you can match on.
| Route kind | Layer the Gateway inspects | Listener protocol | Match options | Release channel |
|---|---|---|---|---|
| HTTPRoute | HTTP request | HTTP, HTTPS | Host, path, header, query, method | Standard |
| GRPCRoute | gRPC over HTTP/2 | HTTP, HTTPS | Host, service, method, header | Standard in recent releases |
| TLSRoute | TLS handshake (SNI) | TLS | SNI hostname | Experimental |
| TCPRoute | None, bytes only | TCP | None, port only | Experimental |
Check the channel and version table for your installed release before you depend on a kind. A route kind in the experimental channel can change in incompatible ways.
GRPCRoute
gRPC runs over HTTP/2, and an HTTPRoute can already forward it. GRPCRoute adds matching on gRPC concepts. You match on the service name and method name instead of building path strings such as /com.example.User/Get.
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: user-grpc
namespace: shop-team
spec:
parentRefs:
- name: web-gateway
namespace: infra
hostnames:
- grpc.example.com
rules:
- matches:
- method:
service: com.example.User
method: GetUser
backendRefs:
- name: user-svc
port: 9090This rule sends calls to com.example.User/GetUser on grpc.example.com to port 9090 of user-svc. If you omit method, the rule matches every method of the service.
TLSRoute
A TLSRoute routes encrypted traffic by the SNI (Server Name Indication) hostname in the TLS handshake. The Gateway does not read the HTTP request, so path and header matching are unavailable.
The listener protocol decides whether the Gateway decrypts. With tls.mode: Passthrough, the Gateway forwards the encrypted stream and the backend holds the certificate. With Terminate, the Gateway decrypts and forwards plain TCP.
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TLSRoute
metadata:
name: db-tls
namespace: shop-team
spec:
parentRefs:
- name: tls-gateway
namespace: infra
sectionName: tls
hostnames:
- db.example.com
rules:
- backendRefs:
- name: db-svc
port: 5432The sectionName field attaches the route to one listener named tls. The Gateway needs a listener with protocol: TLS and tls.mode: Passthrough for this to bind.
TCPRoute
A TCPRoute forwards every connection that arrives on a listener port to a backend. There are no hostnames and no matches, so each TCP listener usually serves one route. Use it for protocols the Gateway cannot parse, such as a database or a message broker.
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TCPRoute
metadata:
name: broker
namespace: shop-team
spec:
parentRefs:
- name: tcp-gateway
namespace: infra
sectionName: broker
rules:
- backendRefs:
- name: broker-svc
port: 5672Common errors
- Protocol mismatch. A route kind must match the listener protocol. A TCPRoute cannot attach to an HTTP listener. The route's parent status shows
Accepted: False. - Unsupported kind. A controller implements only some route kinds. The listener's
supportedKindsstatus lists what it accepts. - Missing CRDs. The experimental route kinds are not in the standard install. Without their CRDs,
kubectl applyfails. - Wrong expectations of features. Weights and cross-namespace
ReferenceGrantrules still apply. Header filters do not, because the Gateway cannot see headers on TLS or TCP traffic.
Exercise
A team wants to expose a PostgreSQL database through a Gateway, and the database presents its own TLS certificate. Which route kind and listener mode fit, and why can't the team route by URL path?
Show answer
Use a TLSRoute on a listener with protocol TLS and tls.mode Passthrough. The Gateway forwards the encrypted stream and matches on the SNI hostname, and the database keeps its certificate. Path routing is impossible because the Gateway never decrypts the traffic, so it cannot see an HTTP request.