簡體   English   中英

連接Google App Engine和Google Compute Engine

[英]connect Google App Engine and Google Compute Engine

我在Googl Compute Engine和Google App Engine標准環境中的應用程序中創建了VM實例。 我打算將我的應用程序放在App Engine中,並將數據庫服務器放在Compute Engine中。 但是,我無法通過內部IP在兩者之間建立連接。 這可能嗎? 該應用程序和數據庫位於同一區域( us-east1 ),但通過IP的連接不起作用,僅適用於外部IP。 顯然,防火牆規則是正確的。

為了通過私有IP連接,您需要將應用程序和數據庫放在同一網絡中。 使用App Engine標准無法實現這一點,您需要為此使用App Engine Flex(請參閱此處,如何設置App Engine Flex實例的網絡)

您將必須使用在Compute Engine實例上運行的服務的外部IP地址進行連接。 App Engine標准環境與Compute Engine實例位於不同的網絡上,並且目前彼此之間沒有私有IP訪問。 如果相關費用合理,則在靈活環境上切換到應用程序(或應用程序的服務)可能對您有用。

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

注意:您可以在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 beta部署服務。 您可以通過運行gcloud組件install beta來訪問beta命令。

部署服務后,它可以將請求發送到內部IP地址DNS名稱 ,以訪問VPC網絡中的資源。 萬一遇到任何麻煩,請等待大約一小時或更長時間,以使連接器在GCP全球網絡中完全傳播。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM