Ingress gRPC Example

The example ingress configuration in grpc-ingress.yaml shows how to route gRPC traffic to backend services.

Deploy the Demo App

For this demo we will use GCP’s microservices demo app.

$ kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/microservices-demo/main/release/kubernetes-manifests.yaml

Since gRPC is binary-encoded, you also need the proto definitions for the gRPC services in order to make gRPC requests. Download this for the demo app:

$ curl -o demo.proto https://raw.githubusercontent.com/GoogleCloudPlatform/microservices-demo/main/protos/demo.proto

Deploy GRPC Ingress

You’ll find the example Ingress definition in examples/kubernetes/servicemesh/grpc-ingress.yaml.

# GRPC ingress for GCP microservice demo application
# https://github.com/GoogleCloudPlatform/microservices-demo
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: grpc-ingress
  namespace: default
spec:
  ingressClassName: cilium
  rules:
  - http:
      paths:
      - backend:
          service:
            name: productcatalogservice
            port:
              number: 3550
        path: /hipstershop.ProductCatalogService
        pathType: Prefix
      - backend:
          service:
            name: currencyservice
            port:
              number: 7000
        path: /hipstershop.CurrencyService
        pathType: Prefix
$ kubectl apply -f https://raw.githubusercontent.com/cilium/cilium/1.15.4/examples/kubernetes/servicemesh/grpc-ingress.yaml

This defines paths for requests to be routed to the productcatalogservice and currencyservice microservices.

Just as in the previous HTTP Ingress Example, this creates a LoadBalancer service, and it may take a little while for your cloud provider to provision an external IP address.

$ kubectl get ingress
NAME           CLASS    HOSTS   ADDRESS         PORTS   AGE
grpc-ingress   cilium   *       10.111.109.99   80      3s

Make gRPC Requests to Backend Services

To issue client gRPC requests you can use grpcurl.

$ GRPC_INGRESS=$(kubectl get ingress grpc-ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
# To access the currency service:
$ grpcurl -plaintext -proto ./demo.proto $GRPC_INGRESS:80 hipstershop.CurrencyService/GetSupportedCurrencies
#To access the product catalog service:
$ grpcurl -plaintext -proto ./demo.proto $GRPC_INGRESS:80 hipstershop.ProductCatalogService/ListProducts