Skip to main content
logoTetrate Service BridgeVersion: 1.5.x

Configure ServiceRoute for (multi-port, multi-protocol) services

This how-to document will show you how to configure routes to services exposing multiple ports through a single ServiceRoute config.

Scenario

Consider a backend service (named tcp-echo) which exposes two ports, port 9000 and port 9001 over TCP. The service has two versions v1 and v2 and traffic splitting needs to be achieved between these two versions for both the ports. In order to achieve this, a ServiceRoute with port settings for both the ports needs to be configured.

Deploy tcp-echo service

You will need to deploy the tcp-echo application from the Istio's samples directory into the echo namespace. Install these manifests to deploy the tcp-echo application.

TSB configuration

Configuring workspace and traffic group

Create a workspace and a traffic group. This assumes that you have already created an organization named tetrateio and a tenant named tetrate.

apiVersion: api.tsb.tetrate.io/v2
kind: Workspace
metadata:
name: tcp-multiport-ws
organization: tetrateio
tenant: tetrate
spec:
namespaceSelector:
names:
- "*/echo"
---
apiVersion: traffic.tsb.tetrate.io/v2
kind: Group
metadata:
name: tcp-multiport-tg
organization: tetrateio
tenant: tetrate
workspace: tcp-multiport-ws
spec:
configMode: BRIDGED
namespaceSelector:
names:
- "*/echo"

Deploy ServiceRoute

Create a file called service-route.yaml with contents similar to the sample below. Note that we are not deploying any gateway(tier-1 or tier-2) in this case because we want to test traffic internally(for use cases such as redis).

apiVersion: traffic.tsb.tetrate.io/v2
kind: ServiceRoute
metadata:
name: tcp-multiport-service-route
organization: tetrateio
tenant: tetrate
workspace: tcp-multiport-ws
group: tcp-multiport-tg
spec:
service: "echo/tcp-echo.svc.cluster.local"
portLevelSettings:
- port: 9000
trafficType: TCP
- port: 9001
trafficType: TCP
subsets:
- name: v1
labels:
version: v1
weight: 80
- name: v2
labels:
version: v2
weight: 20

Testing

To verify that the routes have been set successfully, try curling several times to echo pod. The request will be forwarded to the v1 pod majority of the times because of the 80:20 weight ratio set between v1:v2. For testing TCP traffic, use nc instead.

kubectl -n echo exec -it <pod-name> -c <container-name> -- curl -sv tcp-echo.svc.cluster.local:9000
kubectl -n echo exec -it <pod-name> -c <container-name> -- sh -c “echo hello | nc -v tcp-echo.svc.cluster.local:9001”