我在Google Compute Engine中创建了一个VM实例,并在Google App Engine标准环境中创建了一个应用程序。我计划将我的应用程序放在App Engine中,将我的数据库服务器放在Compute Engine中。但是,我无法通过内部IP连接两者之间的连接。这可能吗?应用程序和数据库都在同一区域(us-east1
),但IP连接不起作用,只能使用外部IP。显然,防火墙规则是正确的。
我在Google Compute Engine中创建了一个VM实例,并在Google App Engine标准环境中创建了一个应用程序。我计划将我的应用程序放在App Engine中,将我的数据库服务器放在Compute Engine中。但是,我无法通过内部IP连接两者之间的连接。这可能吗?应用程序和数据库都在同一区域(us-east1
),但IP连接不起作用,只能使用外部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
$ 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
若要通过私有IP连接,您需要应用程序和数据库在同一网络中。 对于这个问题,您不能使用app engine standard版,必须使用app engine flex版(请参见此处以了解如何设置您的app engine flex实例的网络)。