Configure a Route to gRPC Service
Route to gRPC Service
Prerequisites
- Higress is installed in the higress-system namespace in K8s, with HTTP port listening on 80. For testing convenience, the gateway port is mapped to local 127.0.0.1:80;
- The goal is to deploy the grpc-httpbin service in the default namespace, with the service listening on port 9091;
- For details about the grpc-httpbin service, please refer to github httpbin;
- For the grpcurl tool, please refer to github grpcurl;
Prepare the Backend grpc-httpbin Service
apiVersion: v1kind: Servicemetadata: name: grpc-httpbin-v1 namespace: defaultspec: selector: app: grpc-httpbin-v1 ports: - protocol: TCP port: 9091 targetPort: 9091---apiVersion: apps/v1kind: Deploymentmetadata: name: grpc-httpbin-v1 namespace: default labels: app: grpc-httpbin-v1spec: replicas: 1 selector: matchLabels: app: grpc-httpbin-v1 template: metadata: labels: app: grpc-httpbin-v1 spec: containers: - name: grpc-httpbin-v1 image: registry.cn-hangzhou.aliyuncs.com/2456868764/httpbin:v1.0.1 env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace resources: requests: cpu: 10m
Configure the Route
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: annotations: nginx.ingress.kubernetes.io/backend-protocol: "GRPC" name: ingress-grpc-httpbin namespace: defaultspec: ingressClassName: higress rules: - host: foo.com http: paths: - path: / pathType: Prefix backend: service: name: grpc-httpbin-v1 port: number: 9091
The nginx.ingress.kubernetes.io/backend-protocol
Ingress Annotation specifies the protocol used by the backend service. The default is HTTP, and it supports HTTP, HTTP2, HTTPS, GRPC, and GRPCS.
Testing with grpcurl
- List the backend services
grpcurl -plaintext -authority foo.com 127.0.0.1:80 list
grpc.reflection.v1.ServerReflectiongrpc.reflection.v1alpha.ServerReflectionorder.OrderManagement
- Call the sayHello method
grpcurl -plaintext -authority foo.com -d '{"name": "jun"}' 127.0.0.1:80 order.OrderManagement/sayHello
"Hello jun"