【问题标题】:Connecting to Cloud SQL with Private IP from GCE or GKE使用 GCE 或 GKE 的私有 IP 连接到 Cloud SQL
【发布时间】:2020-01-01 18:22:26
【问题描述】:

我正在尝试使用私有 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 地址吗?

【问题讨论】:

    标签: google-cloud-platform google-compute-engine google-cloud-sql


    【解决方案1】:

    私有 IP 是指通过 Virtual Private Cloud (VPC) 访问 Cloud SQL。您必须使用也在该 VPC 上的资源(在本例中为 GCE 实例)才能访问它。请参阅私有 IP 文档的 environment requirements 页面。

    未来读者请注意:将公共 IP 地址上的 0.0.0.0/0 列入白名单是一个非常糟糕的主意。这实质上允许整个互联网尝试连接到您的实例,并且不应在任何延长的时间内保持启用状态。

    【讨论】:

    • 感谢您的回复,我使用 0.0.0.0/0 只是为了测试目的。
    【解决方案2】:

    您的 gke 集群位于 europe-west1-b。假设您使用默认网络,您必须为 europe-west1 子网启用 Private Google Access。点击子网查看详细信息并在需要时对其进行编辑以将 Private Google Access 设置为“On”。

    【讨论】:

      【解决方案3】:

      几个小时后,我通过为 VM 实例启用 CloudSql 访问范围来建立连接。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-11-24
        • 1970-01-01
        • 1970-01-01
        • 2019-12-28
        • 2021-01-28
        • 1970-01-01
        • 2020-11-27
        相关资源
        最近更新 更多