I have a service that runs REST and gRPC servers on two different ports in a container. I want to be able to expose both the ports instead of running the same service twice one with gRPC and one with REST. Is there any solution?
Some notes about the services:
- Both REST and gRPC are started up when container is deployed.
- They have different startup logic
- When changes are made most of the time it affects both GRPC and REST.
- A majority of the code changed is in the services which both GRPC and REST use.
So having said this, should running the REST and gRPC separately makes more sense or have it in the same container. The other challenge is we want the gRPC server to be accessible only to internal services running that project and REST is accessible to public proxied via nginx server.
Please share your thoughts. Thanks!
2
Answers
You cannot proxy two ports for a Cloud Run application. Your application can listen on as many ports as it wants, but only one port can be proxied.
The Cloud Run frontend exposes ports 80 (HTTP) and 443 (HTTPS). If a client connects to port 80, the client will be redirected to port 443. Your application must listen on the configured port number (default is 8080). Cloud Run then proxies requests on port 443 to your application’s configured port.
Based on the details in your question, I would deploy two Cloud Run services.
Have a look at Cloud Endpoints: https://cloud.google.com/endpoints
It might require tweaking your design a bit. If you set it up right you only need to deploy one Cloud Run service that can handle gRPC requests and let Cloud Endpoints transcode and forward RESTful requests to it: https://cloud.google.com/endpoints/docs/grpc/transcoding
It can also handle authentication: https://cloud.google.com/endpoints/docs/grpc/authentication-method