TCPRoute and UDPRoute in Gateway API v1.6: What You Need to Know
The introduction of TCPRoute and UDPRoute in Gateway API v1.6 is a game changer for Kubernetes networking. By allowing you to route traffic based on protocol and port alone, these resources eliminate the need for Layer 7 awareness, making your configurations cleaner and more efficient. This is particularly useful for services that operate at the transport layer, where application-level routing isn't necessary.
To implement TCPRoute, you start by defining a Gateway with a listener that permits TCPRoute attachments. For example, you can create a Gateway that listens on port 12345 and allows TCPRoute connections. Then, you attach a TCPRoute to that listener, which forwards traffic to a specified backend service. The YAML configuration for this is straightforward, as shown in the examples. Similarly, UDPRoute follows the same pattern, allowing you to route UDP traffic in a comparable manner.
In production, remember that the XBackend API is still experimental. Its behavior may change, so avoid relying on it for critical services until it stabilizes. The v1.6 release deprecated the v1alpha2 versions of these routes, so ensure you're using the latest configurations to avoid compatibility issues.
Key takeaways
- →Utilize TCPRoute to route traffic based on protocol and port without Layer 7 awareness.
- →Define a Gateway with listeners to attach TCPRoute and UDPRoute for efficient traffic management.
- →Be cautious with the experimental XBackend API; its behavior can change unexpectedly.
Why it matters
This update simplifies traffic management in Kubernetes, allowing engineers to focus on core functionality without the overhead of Layer 7 routing complexities. It streamlines configurations, making deployments faster and less error-prone.
Code examples
1apiVersion: gateway.networking.k8s.io/v1
2kind: Gateway
3metadata:
4 name: example-gateway
5spec:
6 gatewayClassName: example-gateway-class
7 listeners:
8 - name: foo
9 protocol: TCP
10 port: 12345
11 allowedRoutes:
12 kinds:
13 - kind: TCPRoute1apiVersion: gateway.networking.k8s.io/v1
2kind: TCPRoute
3metadata:
4 name: tcp-app
5spec:
6 parentRefs:
7 - name: example-gateway
8 sectionName: foo
9 rules:
10 - backendRefs:
11 - name: my-foo-service
12 port: 60001apiVersion: gateway.networking.k8s.io/v1
2kind: Gateway
3metadata:
4 name: example-gateway
5spec:
6 gatewayClassName: example-gateway-class
7 listeners:
8 - name: foo
9 protocol: UDP
10 port: 12345
11 allowedRoutes:
12 kinds:
13 - kind: UDPRouteWhen NOT to use this
The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.
Want the complete reference?
Read official docsIndustry-standard certifications built by the people behind Linux and Kubernetes. Earn the CKA — the gold standard Kubernetes administrator cert. OpsCanary readers get 30% off year-round with code OPSCANARY3.
Get CKA certified →Deploying Dragonfly Lightweight: P2P Distribution Without the Database Overhead
Tired of heavyweight database stacks slowing down your deployments? Discover how a lightweight Dragonfly deployment leverages Kubernetes primitives like ConfigMaps and headless Services for efficient P2P distribution. This approach simplifies your architecture while maintaining performance.
K8gb: Elevating Global Load Balancing in Kubernetes
K8gb is now a CNCF incubating project, marking a significant step in cloud-native global server load balancing. It automates traffic management and ensures seamless failover using Kubernetes-native health checks and CoreDNS.
Injecting Chaos: My LFX Mentorship with kgateway
Chaos engineering is essential for resilient systems, and kgateway makes it easier to implement. I focused on adding HTTP fault injection support, enabling teams to test their services against real-world failures. This article dives into how I achieved this and what you need to know to leverage it effectively.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.