Skip to content

Commit

Permalink
Merge pull request #808 from shaneutt/shaneutt/update-tcp-guide-v1alpha2
Browse files Browse the repository at this point in the history
docs: update tcp guide for v1alpha2
  • Loading branch information
k8s-ci-robot authored Aug 24, 2021
2 parents b5f5435 + c20ba93 commit 26ef98d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 17 deletions.
45 changes: 45 additions & 0 deletions examples/v1alpha2/basic-tcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: Gateway
metadata:
name: my-tcp-gateway
spec:
gatewayClassName: my-tcp-gateway-class
listeners:
- name: foo
protocol: TCP
port: 8080
routes:
kinds:
- kind: TCPRoute
- name: bar
protocol: TCP
port: 8090
routes:
kinds:
- kind: TCPRoute
---
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TCPRoute
metadata:
name: tcp-app-1
spec:
parentRefs:
- name: my-tcp-gateway
sectionName: foo
rules:
- backendRefs:
- name: my-foo-service
port: 6000
---
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TCPRoute
metadata:
name: tcp-app-2
spec:
parentRefs:
- name: my-tcp-gateway
sectionName: bar
rules:
- backendRefs:
- name: my-bar-service
port: 6000
63 changes: 46 additions & 17 deletions site-src/v1alpha2/guides/tcp.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@

!!! danger
This page has not been updated for v1alpha2 yet.

Gateway API is designed to work with multiple protocols.
[TCPRoute](/v1alpha2/v1alpha2/references/spec/#gateway.networking.k8s.io/v1alpha2.TCPRoute) is one such route which
allows for managing TCP traffic.
Gateway API is designed to work with multiple protocols and [TCPRoute][tcproute]
is one such route which allows for managing [TCP][tcp] traffic.

In this example, we have one Gateway resource and two TCPRoute resources that
distribute the traffic with the following rules:
Expand All @@ -14,17 +9,51 @@ distribute the traffic with the following rules:
- All TCP streams on port 8090 of the Gateway are forwarded to port 6000 of
`my-bar-service` Kubernetes Service.

Please note the following:
In this example two `TCP` listeners will be applied to the [Gateway][gateway]
in order to route them to two separate backend `TCPRoutes`, note that the
`protocol` set for the `listeners` on the `Gateway` is `TCP`:

```
{% include 'v1alpha2/basic-tcp.yaml' %}
```

- The `protocol` of listeners on the Gateway is `TCP`.
- Each listener selects exactly one TCPRoute. This is important since the routing
decision is performed based on destination port only. If more metadata is used
for routing decisions, then one may associate multiple TCPRoutes to a single
Gateway listener. Implementations can support such use-cases by adding a custom
resource to specify advanced routing properties and then referencing it in
`spec.rules[].matches[].extensionRef`. Conflicts due to routing colisions should
be resolved as per the [conflict resolution](/v1alpha2/concepts/guidelines#conflicts) guidelines.
In the above example we separate the traffic for the two separate backend TCP
[Services][svc] by using the `sectionName` field in the `parentRefs`:

```yaml
spec:
parentRefs:
- name: my-tcp-gateway
sectionName: foo
```
{% include 'v1alpha1/basic-tcp.yaml' %}
This corresponds directly with the `name` in the `listeners` in the `Gateway`:

```yaml
listeners:
- name: foo
protocol: TCP
port: 8080
- name: bar
protocol: TCP
port: 8090
```

In this way each `TCPRoute` "attaches" itself to a different port on the
`Gateway` so that the service `my-foo-service` is taking traffic for port `8080`
from outside the cluster and `my-bar-service` takes the port `8090` traffic.

## Alternatives: TCP Traffic Routing Using Metadata

While in the above examples we mainly focused on routing by port, it is also
possible to use metadata to route traffic from the `Gateway` to the underlying
`TCPRoutes` using `spec.rules[].matches[].extensionRef`.

See the [spec][tcproute] for more details on how to configure alternative logic
for routing TCP traffic beyond just using ports and selecting `listener` names.

[tcproute]:/v1alpha2/v1alpha2/references/spec/#gateway.networking.k8s.io/v1alpha2.TCPRoute
[tcp]:https://datatracker.ietf.org/doc/html/rfc793
[httproute]:/v1alpha2/v1alpha2/references/spec/#gateway.networking.k8s.io/v1alpha2.HTTPRoute
[gateway]:/v1alpha2/v1alpha2/references/spec/#gateway.networking.k8s.io/v1alpha2.Gateway
[svc]:https://kubernetes.io/docs/concepts/services-networking/service/

0 comments on commit 26ef98d

Please sign in to comment.