generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 635
Add documentation for choosing the right Route type #4330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ryurulz
wants to merge
2
commits into
kubernetes-sigs:main
Choose a base branch
from
ryurulz:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+276
−0
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,248 @@ | ||
| # Choosing the Right Route Type for Your Application | ||
|
|
||
| When deploying an application on Kubernetes, one of the first questions developers face is: | ||
|
|
||
| **“Which Route type should I use to expose my service?”** | ||
|
|
||
| Gateway API provides multiple Route kinds—HTTPRoute, GRPCRoute, TLSRoute, TCPRoute, and UDPRoute—each designed for different traffic patterns and application protocols. | ||
|
|
||
| This guide helps you understand: | ||
|
|
||
| - [What to verify on your Gateway before selecting a Route](#1-before-choosing-a-route-check-your-gateway) | ||
| - [How each Route type works and what problems it solves](#2-route-types-explained) | ||
| - [How to choose the right Route type for your application](#3-choosing-the-right-route--decision-table) | ||
| - [When to use HTTPRoute versus TLSRoute for HTTPS traffic](#4-correct-rule-for-https) | ||
| - [What information to confirm with your cluster administrator](#5-what-to-ask-your-administrator) | ||
| - [Examples of each Route type in real deployments](#2-route-types-explained) | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| ## 1. Before Choosing a Route: Check Your Gateway | ||
|
|
||
| Each Gateway declares its listeners, which define the protocols and ports it supports: | ||
|
|
||
| ```yaml | ||
| spec: | ||
| listeners: | ||
| - name: http | ||
| protocol: HTTP | ||
| port: 80 | ||
| - name: https | ||
| protocol: HTTPS | ||
| port: 443 | ||
| - name: tls | ||
| protocol: TLS | ||
| port: 8443 | ||
| - name: tcp | ||
| protocol: TCP | ||
| port: 5432 | ||
| ``` | ||
| Before creating a Route, verify: | ||
|
|
||
| - Does the Gateway support your protocol? | ||
| - Does the Gateway allow the Route kind you want to attach? | ||
| - Does the GatewayClass implementation support that Route type? | ||
|
|
||
| Your Route must match the listener protocol. | ||
|
|
||
| If you're unsure, check: | ||
|
|
||
| - The Gateway YAML | ||
| - Your GatewayClass documentation | ||
| - Your administrator’s networking policies | ||
|
|
||
| --- | ||
|
|
||
| ## 2. Route Types Explained | ||
|
|
||
| ### HTTPRoute (Standard) | ||
|
|
||
| Use this when your application uses HTTP or HTTPS and you want features such as: | ||
|
|
||
| - Path-based routing | ||
| - Hostname or header routing | ||
| - Redirects, rewrites, filters | ||
|
|
||
| Most HTTPS workloads use HTTPRoute because the Gateway terminates TLS. | ||
|
|
||
| Example: | ||
|
|
||
| ```yaml | ||
| kind: HTTPRoute | ||
| spec: | ||
| parentRefs: | ||
| - name: gateway | ||
| rules: | ||
| - matches: | ||
| - path: | ||
| type: PathPrefix | ||
| value: /api | ||
| backendRefs: | ||
| - name: api-backend | ||
| port: 8080 | ||
| ``` | ||
| ### GRPCRoute (Standard) | ||
|
|
||
| Use this when your application uses gRPC and requires routing at the gRPC service or method level. | ||
|
|
||
| This Route type requires HTTP/2 support on the Gateway. | ||
|
|
||
| Example: | ||
|
|
||
| ```yaml | ||
| kind: GRPCRoute | ||
| spec: | ||
| parentRefs: | ||
| - name: gateway | ||
| rules: | ||
| - matches: | ||
| - method: | ||
| service: payments.Service | ||
| method: Charge | ||
| backendRefs: | ||
| - name: payments-backend | ||
| port: 50051 | ||
| ``` | ||
| ### TLSRoute (Promoted) | ||
|
|
||
| Use this when your application uses TLS and you want the Gateway to pass encrypted traffic directly to the backend without decrypting it. | ||
|
|
||
| Common scenarios include: | ||
|
|
||
| - End-to-end TLS encryption | ||
| - Applications that manage their own certificates | ||
| - Routing based only on the SNI (TLS hostname) | ||
|
|
||
| TLSRoute does not support HTTP-level routing such as paths or headers. | ||
| Use this only when the Gateway should not terminate TLS. | ||
|
|
||
| Example: | ||
|
|
||
| ```yaml | ||
| kind: TLSRoute | ||
| spec: | ||
| parentRefs: | ||
| - name: gateway | ||
| rules: | ||
| - matches: | ||
| - snis: ["secure.example.com"] | ||
| backendRefs: | ||
| - name: secure-app | ||
| port: 8443 | ||
| ``` | ||
| ### TCPRoute (Experimental) | ||
|
|
||
| Use this when your application communicates using raw TCP. | ||
|
|
||
| Common examples include: | ||
|
|
||
| - Databases such as Postgres or MySQL | ||
| - Message brokers such as MQTT or AMQP | ||
| - Mail protocols like SMTP or IMAP | ||
|
|
||
| TCPRoute provides simple Layer-4 forwarding without HTTP or TLS inspection. | ||
|
|
||
| Example: | ||
|
|
||
| ```yaml | ||
| kind: TCPRoute | ||
| spec: | ||
| parentRefs: | ||
| - name: gateway | ||
| backendRefs: | ||
| - name: postgres | ||
| port: 5432 | ||
| ``` | ||
| ### UDPRoute (Experimental) | ||
|
|
||
| Use this when your application uses UDP. | ||
|
|
||
| Common examples include: | ||
|
|
||
| - DNS servers | ||
| - Game servers | ||
| - RTP or other streaming workloads | ||
|
|
||
| UDPRoute forwards packets at Layer 4 without connection state or protocol inspection. | ||
|
|
||
| Example: | ||
|
|
||
| ```yaml | ||
| kind: UDPRoute | ||
| spec: | ||
| parentRefs: | ||
| - name: gateway | ||
| backendRefs: | ||
| - name: dns-backend | ||
| port: 53 | ||
| ``` | ||
| ## 3. Choosing the Right Route — Decision Table | ||
|
|
||
| The table below provides a quick reference for selecting the appropriate Route type based on your application's protocol and routing needs. | ||
|
|
||
| | Application Type | Route Type | Reason | | ||
| |------------------------|------------|-------------------------------| | ||
| | Website / REST API | HTTPRoute | Layer-7 routing, TLS termination | | ||
| | gRPC service | GRPCRoute | Service and method-based routing | | ||
| | HTTPS passthrough | TLSRoute | Backend terminates TLS | | ||
| | Database | TCPRoute | Raw TCP protocol | | ||
| | DNS | UDPRoute | Uses UDP | | ||
| | Game server | UDPRoute | Uses UDP | | ||
|
|
||
|
Comment on lines
167
to
176
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also reuse the Route summary table from https://gateway-api.sigs.k8s.io/concepts/api-overview/#route-summary-table, which includes the "Routing Discriminator" column - the idea of Routing Discriminators is really important for understanding which Route to use. |
||
| ## 4. Correct Rule for HTTPS | ||
|
|
||
| Choosing between HTTPRoute and TLSRoute for HTTPS traffic depends on how TLS is handled by the Gateway. | ||
|
|
||
| ### When the Gateway terminates TLS | ||
| Use **HTTPRoute**. | ||
|
|
||
| This allows the Gateway to inspect the HTTP request and apply features such as: | ||
|
|
||
| - Path matching | ||
| - Hostname-based routing | ||
| - Header-based routing | ||
| - Redirects, rewrites, and filters | ||
|
|
||
| ### When the Gateway passes TLS through | ||
| Use **TLSRoute**. | ||
|
|
||
| In this case: | ||
|
|
||
| - The Gateway does not decrypt the TLS traffic | ||
| - Only SNI-based routing is possible | ||
| - The backend service is responsible for terminating TLS | ||
|
|
||
| TLSRoute is not used for plain-text traffic. | ||
|
|
||
| ## 5. What to Ask Your Administrator | ||
|
|
||
| Before creating a Route, confirm the following details with your administrator or platform team: | ||
|
|
||
| ### Gateway capabilities | ||
| - Which listener protocols are enabled? | ||
| - Does HTTPS terminate TLS or use passthrough? | ||
| - Are TCP or UDP listeners exposed? | ||
|
|
||
| ### Allowed Route types | ||
| Check whether the Gateway restricts which Route kinds can attach to its listeners, using the `allowedRoutes` field. | ||
|
|
||
| ### Implementation support | ||
| - Does the GatewayClass implementation support GRPCRoute? | ||
| - Are experimental Route types such as TCPRoute or UDPRoute enabled? | ||
| - Are there restrictions on using TLS passthrough in production environments? | ||
|
|
||
| ## 6. Summary | ||
|
|
||
| Choosing the correct Route type depends on understanding how your application communicates and how your Gateway is configured. | ||
|
|
||
| Key factors include: | ||
|
|
||
| 1. The protocol your application uses | ||
| 2. Whether TLS is terminated at the Gateway or passed through | ||
| 3. The listener protocols exposed by the Gateway | ||
| 4. The capabilities of your GatewayClass implementation | ||
| 5. Any networking or security policies enforced in your cluster | ||
|
|
||
| By matching your workload to the appropriate Route type, you ensure correct traffic handling and take advantage of the routing features provided by Gateway API. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should actually be combined with the "what to ask your administrator" section, as they are essentially saying the same thing.
I think that it's better to start this page with outlining the different Route types and what problems it solves.