簡體   English   中英

通過GCE或GKE使用私有IP連接到Cloud SQL

[英]Connecting to Cloud SQL with Private IP from GCE or GKE

我正在嘗試使用私有IP通過部署​​在GoogleCompute集群中的Pod連接到Postgres數據庫(CloudSQL),但僅收到連接超時錯誤。

我使用以下命令設置了GCP集群:

gcloud beta container clusters create "gcp-cluster" --zone "europe-west1-b" --no-enable-basic-auth --cluster-version "1.13.6-gke.13" --machine-type "n1-standard-1" --image-type "COS" --disk-type "pd-ssd" --disk-size "20" --metadata disable-legacy-endpoints=true --scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append","https://www.googleapis.com/auth/sqlservice.admin","https://www.googleapis.com/auth/sqlservice" --num-nodes "2" --enable-stackdriver-kubernetes --enable-ip-alias --network "projects/XXX/global/networks/default" --subnetwork "projects/XXX/regions/europe-west1/subnetworks/default" --default-max-pods-per-node "110" --enable-autoscaling --min-nodes "2" --max-nodes "20" --addons HorizontalPodAutoscaling,HttpLoadBalancing --enable-autoupgrade --enable-autorepair --maintenance-window "19:00"

然后,我部署了一個指向postgres數據庫IP地址(在同一區域/區域中創建的數據庫)的Wildfly,但是我只得到了連接超時。 使用源0.0.0.0/0啟用公共IP地址后,我可以建立連接。

有使用私有IP地址的想法嗎?

私有IP意味着通過虛擬私有雲 (VPC)訪問Cloud SQL。 您必須使用該VPC上的資源(在本例中為GCE實例)才能訪問該資源。 請參閱專用IP文檔的環境要求頁面。

敬請以后的讀者注意:在公共IP地址上將0.0.0.0/0列入白名單是一個非常糟糕的主意。 這實質上允許整個Internet嘗試連接到您的實例,並且不應在任何長時間內保持啟用狀態。

您的gke集群位於europe-west1-b。 假設您使用默認網絡,則必須為europe-west1子網啟用私有Google訪問。 單擊子網以查看詳細信息,並根據需要對其進行編輯,以將“ 私有Google訪問 ”設置為“ ”。

幾個小時后,我通過為VM實例啟用CloudSql訪問范圍來建立連接。

暫無
暫無

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

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