ingress does not work with GRPC gateway. HTTP requests are not being forwarded to GRPC gateway as expected by the ingress

7/13/2020

I have set up a GRPC gateway with all the methods corresponding to HTTP URLs. e.g. v1/my-service. These paths do not seem to work for the ingress I have set up. I can send a request indirectly by using another pod to route the requests to this URL using the internal cluster IP however when I try to go directly my-ip/v1/myservice I get a server error with little description:

Error: Server Error</h1>
<h2>The server encountered a temporary error and could not complete your request.<p>Please try again in 30 seconds.

Is there a reason why this occurs? I can't see why I get server errors this way when I know that the incoming URL format corresponds to the method defined in the gateway. I would like to point out that my ingress definitely works as I am simply using this intermediary pod to route the successful requests but I am still sending them through the ingress.

-- user10486019
google-kubernetes-engine
grpc
grpc-gateway
kubernetes
kubernetes-ingress

1 Answer

7/13/2020

Possibly, you need the annotation on your Ingress resource(?):

nginx.ingress.kubernetes.io/backend-protocol: "GRPC"

and the HTTP/2 ingress controller ConfigMap option(?):

use-http2="true"

Also, check the nginx.conf in the Nginx ingress controller pod:

kubectl exec -it <nginx-ingress-pod> sh
# cat nginx.conf

You want to check that something like this is configured at the server level:

    server {
        listen 80 http2;
 
        access_log logs/access.log main;
 
        location / {
            # Replace localhost:50051 with the address and port of your gRPC server
            # The 'grpc://' prefix is optional; unencrypted gRPC is the default
            grpc_pass grpc://localhost:50051;
        }
    }
-- Rico
Source: StackOverflow