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 docsUnified observability — logs, uptime monitoring, and on-call in one place. Used by 50,000+ engineering teams to ship faster and sleep better.
Try Better Stack free →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.
Seamlessly Access Private Git Repositories in EKS with Argo CD
Unlock the power of Argo CD by integrating it with private Git repositories hosted on AWS. Learn how to set up AWS CodeConnections to create a secure network path for your Git server, ensuring smooth deployment workflows.
Mastering Full Request and Response Logging on Amazon EKS
In a world where compliance is non-negotiable, capturing full request and response data is crucial. Learn how Envoy’s External Processing filter enables this without altering your application code.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.