TLSRoute¶
Overview¶
TLSRoute is a Gateway API resource that routes Transport Layer Security (TLS) traffic within a Kubernetes cluster. It forwards encrypted traffic to backend services without ending the TLS session at the gateway. This is called TLS passthrough.
TLSRoute uses the Server Name Indication (SNI) field in the TLS ClientHello message to make routing decisions. This lets you direct traffic to the correct backend based on the hostname the client requests.
Note
TLSRoute support is introduced with the 1.5.0 standard Gateway API bundle. It has graduated to the standard channel and does not require the experimental bundle.
Key aspects of TLSRoute:¶
TLS passthrough routing: The gateway forwards encrypted TLS traffic end-to-end to backend services without terminating the TLS session.
SNI-based routing: The system routes traffic based on the SNI hostname in the TLS ClientHello message.
Wildcard hostnames: Supports wildcard hostnames (for example,
*.example.com) for Gateway listeners and TLSRoute hostnames.Cross-namespace support: The
TLSRouteuses aReferenceGrantto reference backend services in different namespaces.
Note
Weighted traffic distribution across multiple backendRefs is not supported.
Update a backend service¶
When you edit a backend service, the dataplane configuration does not update automatically. Follow these steps:
Delete the service.
Modify the YAML file of the service.
Reapply the service.
Note
Perform Custom Resource (CR) operations only when the controller is in a running state.
TLSRoute status¶
Accepted¶
conditions.status |
conditions.reason |
Description |
|---|---|---|
Unknown |
Pending |
Initial state. Waiting for the controller. |
True |
Accepted |
The route is accepted. |
False |
- NoMatchingParent |
- No matching parents by name, port, or section name. |
ResolvedRefs¶
conditions.status |
conditions.reason |
Description |
|---|---|---|
True |
ResolvedRefs |
All references are resolved. |
False |
- InvalidKind |
- The |
PartiallyInvalid¶
conditions.status |
conditions.reason |
Description |
|---|---|---|
True |
UnsupportedValue |
The route contains both valid and invalid rules. |
Note
The descriptions in these tables may not match the exact text in the status section of the CR.
Examples¶
This section lists sample CRs for common TLSRoute use cases.
Basic TLSRoute¶
The Gateway listener uses hostname: "*.example.com" to accept any subdomain. The TLSRoute attaches to this listener through sectionName and specifies the exact SNI hostname abc.example.com. The controller generates an SNI-based traffic policy rule that forwards matching TLS connections to the backend service without terminating TLS at the gateway.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: f5-tls-gateway
namespace: gateway-infra
spec:
infrastructure:
parametersRef:
group: gateway.k8s.f5.com
kind: GatewaySettings
name: gw-settings-tls
gatewayClassName: f5-gateway-class
listeners:
- name: tls
protocol: TLS
port: 443
hostname: "*.example.com"
tls:
mode: Passthrough
allowedRoutes:
namespaces:
from: "All"
kinds:
- kind: TLSRoute
---
apiVersion: gateway.networking.k8s.io/v1
kind: TLSRoute
metadata:
name: my-tlsroute
namespace: app-ns
spec:
parentRefs:
- name: f5-tls-gateway
sectionName: tls
namespace: gateway-infra
hostnames:
- "abc.example.com"
rules:
- backendRefs:
- name: tls-backend-service
port: 443
namespace: app-ns
TLSRoute with wildcard hostname¶
When the TLSRoute specifies a wildcard hostname (for example, *.example.com), the controller generates a wildcard SNI condition using a suffix match. Any TLS ClientHello with a server name ending in .example.com is forwarded to the backend. The Gateway listener hostname must encompass the route hostname for the route to be accepted.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: f5-tls-gateway
namespace: gateway-infra
spec:
infrastructure:
parametersRef:
group: gateway.k8s.f5.com
kind: GatewaySettings
name: gw-settings-tls
gatewayClassName: f5-gateway-class
listeners:
- name: tls
protocol: TLS
port: 443
hostname: "*.example.com"
tls:
mode: Passthrough
allowedRoutes:
namespaces:
from: "All"
kinds:
- kind: TLSRoute
---
apiVersion: gateway.networking.k8s.io/v1
kind: TLSRoute
metadata:
name: my-tlsroute-wildcard
namespace: app-ns
spec:
parentRefs:
- name: f5-tls-gateway
sectionName: tls
namespace: gateway-infra
hostnames:
- "*.example.com"
rules:
- backendRefs:
- name: tls-backend-service
port: 443
namespace: app-ns
TLSRoute with cross-namespace backend¶
When the TLSRoute and its backend Service are in different namespaces, a ReferenceGrant in the backend namespace must explicitly permit the cross-namespace reference. Without it, the route status shows ResolvedRefs=False with reason RefNotPermitted.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: f5-tls-gateway
namespace: gateway-infra
spec:
infrastructure:
parametersRef:
group: gateway.k8s.f5.com
kind: GatewaySettings
name: gw-settings-tls
gatewayClassName: f5-gateway-class
listeners:
- name: tls
protocol: TLS
port: 443
hostname: "*.example.com"
tls:
mode: Passthrough
allowedRoutes:
namespaces:
from: "All"
kinds:
- kind: TLSRoute
---
apiVersion: gateway.networking.k8s.io/v1
kind: TLSRoute
metadata:
name: my-tlsroute
namespace: gateway-infra
spec:
parentRefs:
- name: f5-tls-gateway
sectionName: tls
namespace: gateway-infra
hostnames:
- "abc.example.com"
rules:
- backendRefs:
- name: tls-backend-service
port: 443
namespace: app-ns # Cross-namespace reference requires a ReferenceGrant
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
name: allow-tlsroute-backend
namespace: app-ns
spec:
from:
- group: gateway.networking.k8s.io
kind: TLSRoute
namespace: gateway-infra
to:
- group: ""
kind: Service
TLSRoute parameters¶
The table below describes the TLSRoute spec parameters.
Parameter |
Description |
Details |
|---|---|---|
|
The name of the parent Gateway resource. For example, |
As per the Gateway API community standard. |
|
The namespace of the parent Gateway resource. When not specified, this refers to the local namespace of the Route. |
As per the Gateway API community standard. |
|
The network port that this TLSRoute targets. For example, |
As per the Gateway API community standard. |
|
The section name of the parent Gateway listener. For example, |
As per the Gateway API community standard. |
|
A list of SNI hostnames to match TLSRoute. For example, |
Used for SNI-based routing on the TLS ClientHello event. |
|
Name of the backend service to which traffic must be sent. For example, |
As per the Gateway API community standard. |
|
Port on which the backend service is listening. For example, |
As per the Gateway API community standard. |
|
The weight for load balancing traffic between multiple backends. |
Not supported. |
|
The namespace of the backend service. When not specified, this refers to the local namespace of the Route. |
As per the Gateway API community standard. |
Note
Refer to TLSRoute for more details.