Configure a TCP Layer-4 Route
Prerequisites
- Higress is installed in the higress-system namespace in K8s, with the gateway’s Service name being higress-gateway;
- The goal is to configure a layer-4 route for the tcp-echo service in the default namespace, with the service listening on port 9000 and the gateway also listening on port 9000;
- The route is configured using Gateway API CRD, which requires Higress to be configured to support Gateway API in advance. Reference documentation: Document
Configuration Steps
1. Create GatewayClass
- Create a
gatewayclass.yaml
file with the following content:apiVersion: gateway.networking.k8s.io/v1kind: GatewayClassmetadata:name: higress-gatewayspec:controllerName: "higress.io/gateway-controller" - Execute the command to apply the configuration to the K8s cluster:
Terminal window kubectl apply -f gatewayclass.yaml
2. Create Gateway
- Create a
gateway.yaml
file with the following content:apiVersion: gateway.networking.k8s.io/v1kind: Gatewaymetadata:name: higress-gatewaynamespace: higress-systemspec:gatewayClassName: higress-gatewaylisteners:- name: default-tcpprotocol: TCPport: 9000allowedRoutes:namespaces:from: Allkinds:- kind: TCPRoute - Execute the command to apply the configuration to the K8s cluster:
Terminal window kubectl apply -f gateway.yaml
3. Modify the higress-gateway
Service
- Execute the command to enter the edit state of the
higress-gateway
Service:Terminal window kubectl edit service higress-gateway -n higress-system - Add a description for port
9000
to thespec.ports
list. The configuration after the addition should look like this:...ports:- name: http2port: 80protocol: TCPtargetPort: 80- name: httpsport: 443protocol: TCPtargetPort: 443# --- Configuration added here ---- name: tcpport: 9000protocol: TCPtargetPort: 9000# -----------------------------... - Save the edits and exit the editor.
4. Create TCPRoute
- Create a
tcproute.yaml
file with the following content:apiVersion: gateway.networking.k8s.io/v1alpha2kind: TCPRoutemetadata:name: tcp-echonamespace: defaultspec:parentRefs:- name: higress-gatewaynamespace: higress-systemport: 9000rules:- backendRefs:- name: tcp-echoport: 9000 - Execute the command to apply the configuration to the K8s cluster:
Terminal window kubectl apply -f tcproute.yaml
5. Configuration Verification
Configuration complete. We can verify whether the route is working properly by using telnet to connect to port 9000 of the higress-gateway service or by other means.