连接 Google App Engine 和 Google Compute Engine

Jua*_*nza 5 google-app-engine google-compute-engine google-cloud-platform

我在 Googl Compute Engine 和 Google App Engine 标准环境中的应用程序中创建了一个 VM 实例。我打算在 App Engine 中使用我的应用程序,在 Compute Engine 中使用我的数据库服务器。但是,我无法通过内部 IP 在两者之间进行连接。这可能吗?app 和 db 在同一个区域 ( us-east1) 但通过 IP 的连接不起作用,只能使用外部 IP。显然,防火墙的规则是正确的。

Che*_*ana 10

2019 年 4 月 9 日起,您可以使用无服务器VPC 连接器

这将允许您的 App Engine 应用程序连接到 Google Cloud Platform 上 VPC 网络中的其他内部资源,例如 Compute Engine VM 实例、Cloud Memorystore 实例以及具有内部 IP 地址的任何其他资源。

要创建连接器:

$ gcloud services enable vpcaccess.googleapis.com
$ gcloud beta compute networks vpc-access connectors create CONNECTOR_NAME \
--network VPC_NETWORK --region REGION --range IP_RANGE
$ gcloud beta compute networks vpc-access connectors describe CONNECTOR_NAME --region REGION
Run Code Online (Sandbox Code Playgroud)

注意:您可以在Google Cloud Platform Console 中查看当前保留的 IP 范围。您可以选择任何未使用的 CIDR /28 IP范围用于您的连接器,例如 10.8.0.0/28。

$ gcloud beta compute networks vpc-access connectors create my-vpc-connector \
--region=us-central1 --range=10.8.0.0/28
Create request issued for: [my-vpc-connector]
Waiting for operation [xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx] to complete...done.  
Created connector [my-vpc-connector]
Run Code Online (Sandbox Code Playgroud)

要将您的连接器连接到服务,请将其添加到您的服务的app.yaml文件中:

vpc_access_connector:
  name: "projects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME"
Run Code Online (Sandbox Code Playgroud)

部署服务:

$ gcloud beta app deploy
Run Code Online (Sandbox Code Playgroud)

注意:要使用无服务器 VPC 访问,请确保您使用 gcloud beta 来部署您的服务。您可以通过运行gcloud components install beta来访问 beta 命令。

部署服务后,它可以向内部 IP 地址DNS 名称发送请求,以便访问VPC 网络中的资源。如果出现任何问题,请等待大约一小时或更长时间,让连接器在 GCP 全球网络中完全传播。


Avi*_*eir 4

要通过私有 IP 连接,您需要应用程序和数据库位于同一网络中。您无法使用 App Engine 标准实现这一点,您需要 App Engine Flex(请参阅此处如何设置 App Engine Flex 实例的网络)