How to expose 2 ports in cloudrun

huangapple go评论94阅读模式
英文:

How to expose 2 ports in cloudrun

问题

我有一个在容器中运行 REST 和 gRPC 服务器的服务。我希望能够同时暴露这两个端口,而不是分别运行带有 gRPC 和 REST 的两个服务。是否有任何解决方案?

关于这些服务的一些说明:

  1. 容器部署时同时启动 REST 和 gRPC。
  2. 它们具有不同的启动逻辑。
  3. 当进行更改时,大部分时间都会影响到 gRPC 和 REST。
  4. 大部分代码更改都是在 gRPC 和 REST 都使用的服务中。

基于这些情况,将 REST 和 gRPC 分别运行是否更合理,还是将它们放在同一个容器中?另一个挑战是,我们希望 gRPC 服务器只能被运行该项目的内部服务访问,而 REST 可以通过 nginx 服务器代理对外公开。

请分享你的想法。谢谢!

英文:

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:

  1. Both REST and gRPC are started up when container is deployed.
  2. They have different startup logic
  3. When changes are made most of the time it affects both GRPC and REST.
  4. 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!

答案1

得分: 1

您无法为Cloud Run应用程序代理两个端口。您的应用程序可以监听任意数量的端口,但只能代理一个端口。

Cloud Run前端公开了端口80(HTTP)和端口443(HTTPS)。如果客户端连接到端口80,客户端将被重定向到端口443。您的应用程序必须监听配置的端口号(默认为8080)。然后,Cloud Run将代理对应用程序配置端口的请求。

根据您问题中的详细信息,我会部署两个Cloud Run服务。

英文:

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.

答案2

得分: 0

请看一下 Cloud Endpoints:https://cloud.google.com/endpoints

这可能需要对你的设计进行一些调整。如果你正确设置了它,你只需要部署一个 Cloud Run 服务来处理 gRPC 请求,并让 Cloud Endpoints 转码和转发 RESTful 请求给它:https://cloud.google.com/endpoints/docs/grpc/transcoding

它还可以处理身份验证:https://cloud.google.com/endpoints/docs/grpc/authentication-method

英文:

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

huangapple
  • 本文由 发表于 2022年9月6日 11:04:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/73616292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定