Skip to content

Commit 8d3c9a7

Browse files
committed
Add route port matching doc
1 parent 1edf7e9 commit 8d3c9a7

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

site-src/api-types/httproute.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,64 @@ spec:
4343
Note that the target Gateway needs to allow HTTPRoutes from the route's
4444
namespace to be attached for the attachment to be successful.
4545
46+
You can also attach routes to specific sections of the parent resource.
47+
For example, let's say that the `acme-lb` Gateway includes the following
48+
listeners:
49+
50+
```yaml
51+
listeners:
52+
- name: foo
53+
protocol: HTTP
54+
port: 8080
55+
...
56+
- name: bar
57+
protocol: HTTP
58+
port: 8090
59+
...
60+
- name: baz
61+
protocol: HTTP
62+
port: 8090
63+
...
64+
```
65+
66+
You can bind a route to listener `foo` only, using the `sectionName` field
67+
in `parentRefs`:
68+
69+
```yaml
70+
spec:
71+
parentRefs:
72+
- name: acme-lb
73+
sectionName: foo
74+
```
75+
76+
Alternatively, you can achieve the same effect by using the `port` field,
77+
instead of `sectionName`, in the `parentRefs`:
78+
79+
```yaml
80+
spec:
81+
parentRefs:
82+
- name: acme-lb
83+
port: 8080
84+
```
85+
86+
Binding to a port also llows you to attach to multiple listeners at once.
87+
For example, binding to port `8090` of the `acme-lb` Gateway would be more
88+
convenient than binding to the corresponding listeners by name:
89+
90+
```yaml
91+
spec:
92+
parentRefs:
93+
- name: acme-lb
94+
sectionName: bar
95+
- name: acme-lb
96+
sectionName: baz
97+
```
98+
99+
However, when binding Routes by port number, Gateway admins will no longer have
100+
the flexibility to switch ports on the Gateway without also updating the Routes.
101+
The approach should only be used when a Route should apply to a specific port
102+
number as opposed to listeners whose ports may be changed.
103+
46104
### Hostnames
47105

48106
Hostnames define a list of hostnames to match against the Host header of the

site-src/guides/tcp.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,24 @@ In this way each `TCPRoute` "attaches" itself to a different port on the
4949
`Gateway` so that the service `my-foo-service` is taking traffic for port `8080`
5050
from outside the cluster and `my-bar-service` takes the port `8090` traffic.
5151

52+
Note that you can achieve this same result by binding the Routes to the Gateway
53+
listeners using the `port` field in the `parentRefs`:
54+
55+
```yaml
56+
spec:
57+
parentRefs:
58+
- name: my-tcp-gateway
59+
port: 8080
60+
```
61+
62+
Using the `port` field instead of `sectionName` for the attachment has the
63+
downside of more tightly coupling the relationship between the Gateway and
64+
its associated Routes. Refer to [Attaching to Gateways][attaching] for more
65+
details.
66+
5267
[tcproute]:/reference/spec/#gateway.networking.k8s.io/v1alpha2.TCPRoute
5368
[tcp]:https://datatracker.ietf.org/doc/html/rfc793
5469
[httproute]:/reference/spec/#gateway.networking.k8s.io/v1alpha2.HTTPRoute
5570
[gateway]:/reference/spec/#gateway.networking.k8s.io/v1alpha2.Gateway
5671
[svc]:https://kubernetes.io/docs/concepts/services-networking/service/
72+
[attaching]:/api-types/httproute/#attaching-to-gateways

0 commit comments

Comments
 (0)