截至April 9, 2019,您可以使用无服务器VPC
connector。
这将允许您的 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
注意:您可以在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]
要将连接器连接到服务,请将其添加到服务的 app.yaml 文件中:
vpc_access_connector:
name: "projects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME"
部署服务:
$ gcloud beta app deploy
注意:要使用无服务器 VPC 访问,请确保您使用 gcloud 测试版来部署您的服务。您可以通过运行 gcloud components install beta 来访问 beta 命令。
部署服务后,它可以向Internal IP addresses 或DNS Names 发送请求,以便访问VPC Networks 中的资源。如果出现任何问题,请等待大约一小时或更长时间,让连接器在 GCP 全球网络中完全传播。