GRPCRoute¶
The GRPCRoute resource in the Kubernetes Gateway API is designed to handle and route gRPC traffic within a Kubernetes cluster. GRPCRoute is determined by the Gateway API community. It extends the capabilities of routing beyond traditional HTTP traffic to support gRPC, a modern and high-performance protocol for remote procedure calls.
Key aspects of the GRPCRoute include:¶
- Routing gRPC Traffic: Defines rules for how gRPC requests must be directed from a Gateway to backend services, specifying how different gRPC methods and services should be mapped to various endpoints.
- Integration: Integrates with the Gateway and other related resources to manage and configure gRPC traffic efficiently.
- Flexibility: Allows for advanced routing configurations, including the use of path-based and header-based routing, which is crucial for complex gRPC service architectures.
By using GRPCRoute, Kubernetes users can effectively manage gRPC traffic, ensuring that requests are routed correctly and efficiently within their cluster.
CR Parameters¶
The table below describes the GRPCRoute spec
parameters:
Parameter | Description |
---|---|
parentRefs.name |
Specifies the parent references of the Gateway. For example, grpc-gateway |
parentRefs.sectionName |
Specifies the listener in the Gateway. For example, grpc |
rules.backendRefs.name |
Specifies the name of the backend service to which the traffic must be forwarded. For example, grpc-echo |
rules.backendRefs.port |
Specifies the port of the backend service. For example, 9000 |
rules.backendRefs.weight |
Specifies the weight associated with the backend service. This determines the proportion of traffic that will be routed to the service. |
rules.matches.method.service |
Specifies the service name that must be matched. |
rules.matches.method.method |
Specifies the method name that must be matched within the service. |
rules.matches.headers.type |
Specifies the type of matching. |
rules.matches.headers.name |
Specifies the name to match the route . |
rules.matches.method.value |
Specify the value of the header to match the Route. |
Note: You can refer to GRPCRoute for more details.
Support Status¶
The following table describes the support status of GRPCRoute CR paremeters:
Parameter | Supported/Not Supported/Optional |
---|---|
parentRefs.name |
Supported |
parentRefs.sectionName |
Supported |
rules.backendRefs.name |
Supported |
rules.backendRefs.port |
Supported |
rules.backendRefs.weight |
Supported |
rules.matches.method.service |
Supported |
rules.matches.method.method |
Supported |
rules.matches.headers.type |
Supported |
rules.matches.headers.name |
Supported |
rules.matches.method.value |
Supported |
Sample CRs¶
- Basic GRPCRoute CR
- GRPCRoute CR for SSL config
- GRPCRoute for method/service based routing
- GRPCRoute for header based routing
- GRPCRoute for traffic weight distribution
Basic GRPCRoute CR¶
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
name: my-grpc-gateway-class
spec:
controllerName: "f5.com/f5-gateway-controller"
description: "F5 BIG-IP grpc route Kubernetes Gateway"
---
apiVersion: gateway.k8s.f5net.com/v1
kind: Gateway
metadata:
name: grpc-gateway
spec:
addresses:
- type: "IPAddress"
value: <IP Address>
gatewayClassName: my-grpc-gateway-class
listeners:
- name: grpc
protocol: HTTP
port: 8088
---
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: grpc-route
spec:
parentRefs:
- name: grpc-gateway
sectionName: grpc
rules:
- backendRefs:
- name: grpc-echo
port: 9000
GRPCRoute CR for SSL config¶
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
name: ssl-grpc-gateway-class
spec:
controllerName: "f5.com/f5-gateway-controller"
description: "F5 BIG-IP grpc route Kubernetes Gateway"
---
apiVersion: gateway.k8s.f5net.com/v1
kind: Gateway
metadata:
name: grpc-gateway
spec:
addresses:
- type: "IPAddress"
value: <IP Address>
gatewayClassName: ssl-grpc-gateway-class
listeners:
- name: grpc
protocol: HTTP
port: 8088
tls:
certificateRefs:
- kind: Secret
group: ""
name: tls-secret
namespace: spk-app-1
---
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: grpc-route
spec:
parentRefs:
- name: grpc-gateway
sectionName: grpc
rules:
- backendRefs:
- name: grpc-echo
port: 9000
GRPCRoute for method/service based routing¶
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
name: my-header-grpc-gateway-class
spec:
controllerName: "f5.com/f5-gateway-controller"
description: "F5 BIG-IP grpc route Kubernetes Gateway"
---
apiVersion: gateway.k8s.f5net.com/v1
kind: Gateway
metadata:
name: header-grpc-gateway
spec:
addresses:
- type: "IPAddress"
value: <IP Address>
gatewayClassName: my-header-grpc-gateway-class
listeners:
- name: grpc
protocol: HTTP
port: 8088
---
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: header-grpc-route
spec:
parentRefs:
- name: header-grpc-gateway
sectionName: grpc
rules:
- matches:
- method:
service: yages.Echo
method: Ping
backendRefs:
- name: grpc-echo
port: 9000
- backendRefs:
- name: spk-app-grpc-8000-f5ing-testapp
port: 8000
GRPCRoute for header based routing¶
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
name: my-header-grpc-gateway-class
spec:
controllerName: "f5.com/f5-gateway-controller"
description: "F5 BIG-IP grpc route Kubernetes Gateway"
---
apiVersion: gateway.k8s.f5net.com/v1
kind: Gateway
metadata:
name: header-grpc-gateway
spec:
addresses:
- type: "IPAddress"
value: <IP Address>
gatewayClassName: my-header-grpc-gateway-class
listeners:
- name: grpc
protocol: HTTP
port: 8088
---
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: header-grpc-route
spec:
parentRefs:
- name: header-grpc-gateway
sectionName: grpc
rules:
- matches:
- headers:
- type: Exact
name: env
value: canary
backendRefs:
- name: grpc-echo
port: 9000
- backendRefs:
- name: spk-app-grpc-8000-f5ing-testapp
port: 8000
GRPCRoute for traffic weight distribution¶
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
name: my-grpc-gateway-class
spec:
controllerName: "f5.com/f5-gateway-controller"
description: "F5 BIG-IP grpc route Kubernetes Gateway"
---
apiVersion: gateway.k8s.f5net.com/v1
kind: Gateway
metadata:
name: grpc-gateway
spec:
addresses:
- type: "IPAddress"
value: <IP Address>
gatewayClassName: my-grpc-gateway-class
listeners:
- name: grpc
protocol: HTTP
port: 8088
---
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: grpc-route
spec:
parentRefs:
- name: grpc-gateway
sectionName: grpc
rules:
- backendRefs:
- name: gen-5nfvb
port: 50051
weight: 60
- name: gen-5nfvc
port: 50052
weight: 40