无法使用内部 IP 在云 运行 和计算引擎之间进行连接

Can not connect between Cloud Run and Compute engine using Internal IP

我有一项在云 运行 上运行的服务,以及 Compute Engine 上的 MYSQL、MongoDB 数据库。目前,我正在使用 public IP 在它们之间进行连接,我想使用内部 IP 来提高性能,但我找不到解决这个问题的方法,请帮我一些想法,谢谢。

根据官方文档Connecting to instances using advanced methods

If you have an isolated instance that doesn't have an external IP address (such as an instance that is intentionally isolated from external networks), you can still connect to it by using its internal IP address on a Google Cloud Virtual Private Cloud (VPC) network

但是,如果您检查 Cloud 运行 尚不支持的服务,您会发现:

Virtual Private Cloud Cloud Run (fully managed) cannot connect to VPC network.

Services not yet supported

从云连接 运行 管理到 VPC 私有地址尚不支持。

此功能正在开发中,称为无服务器 VPC 访问。您可以阅读更多 here.

如果您在具有 public IP 地址的同一 VPC 中有一个 Compute Engine 实例 运行,您可以创建 SSH 隧道以通过 public 连接到私有 IP 地址实例。这需要在您自己的代码中创建隧道,这很容易做到。

现在支持。您可以使用 VPC 网络连接器(测试版):

This feature is in a pre-release state and might change or have limited support. For more information, see the product launch stages.

This page shows how to use Serverless VPC Access to connect a Cloud Run (fully managed) service directly to your VPC network, allowing access to Compute Engine VM instances, Memorystore instances, and any other resources with an internal IP address.

To use Serverless VPC Access in a Cloud Run (fully managed) service, you first need to create a Serverless VPC Access connector to handle communication to your VPC network. After you create the connector, you set your Cloud Run (fully managed) service configuration to use that connector.

创建方法如下:Creating a Serverless VPC Access connector and here an overview about it: Serverless VPC Access example

您现在可以在部署时通过 运行 此命令执行此操作:

gcloud run deploy SERVICE --image gcr.io/PROJECT_ID/IMAGE --vpc-connector CONNECTOR_NAME

如果您已经有云 运行 部署,您可以通过 运行 命令更新它:

cloud run services update SERVICE --vpc-connector CONNECTOR_NAME

更多相关信息here