连接 Google App Engine 和 Google Compute Engine

6

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


链接相关讨论:https://dev59.com/TmIk5IYBdhLWcg3wke7N - blong
3个回答

12
截至2019年4月9日,您可以使用无服务器的VPC连接器。这将允许您的应用程序在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控制台中查看当前保留的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 beta部署您的服务。您可以通过运行gcloud components install beta来获得访问beta命令的权限。
部署服务后,它能够发送请求以访问VPC Networks中的资源,以便访问Internal IP addressesDNS Names。如果遇到任何问题,请允许大约一小时或更长时间使连接器在GCP全局网络中完全传播。

4

若要通过私有IP连接,您需要应用程序和数据库在同一网络中。 对于这个问题,您不能使用app engine standard版,必须使用app engine flex版(请参见此处以了解如何设置您的app engine flex实例的网络)。


您可以在此Google论坛上查看Lorne Kliegerman(App Engine产品经理)的回复:https://groups.google.com/forum/#!topic/google-appengine/P2PK6g4TteY。目前,App Engine标准部署和Compute Engine VM实例之间的直接内部IP地址连接尚不可用。同时,@Avinoam的建议是正确的:您只能为App Engine Flexible配置网络。 - Tudormi

1
你需要使用Compute Engine实例上运行的服务的外部IP地址进行连接。App Engine标准环境与Compute Engine实例位于不同的网络中,目前彼此之间没有私有IP访问。如果相关成本合理,切换到灵活环境中的应用程序(或应用程序的服务)可能适合您。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接