google-cloud-platform - 从另一个 GCP 项目访问 Cloud SQL

标签 google-cloud-platform google-cloud-sql google-cloud-networking

我想从另一个 GCP 项目连接到 Cloud SQL。

Cloud SQL 是 ProjectSQL 中的位置,并且 ProjectSQL 项目中有一个 VPC 网络,名称为 sql_vpc

还有另一个项目 ProjectDataflow,它有一个 vpc dataflow_vpc。我想使用 ProjectDataflow 项目中启动的 VM 从 ProjectSQL 连接到 cloudSQL

我尝试过的事情有成功也有失败。

私有(private)访问:

VPC 对等互连:

Enable Private IP access in Cloud with the vpc sql_vpc
Creating VPC peering between dataflow_vpc and sql_vpc
This solution does not work because you can not access the Peered Network.
https://cloud.google.com/sql/docs/mysql/private-ip
Status: FAILED

共享网络
As per doc I can create the CloudSQL in shared VPC network, that says I 
have to create the CloudSQL in host project, and to access the Cloud 
SQL from  VM instance, it has be in the same network as of authorized 
private ip network of Cloud SQL
Status: NOT TRIED but looks to be Negative

公共(public)访问:
Create a Cloud NAT in ProjectDataflow with dataflow_vpc with manual IP
Use the Cloud NAT public ip to whitelist in CloudSQL instance
Now I can access the CloudSQL from project ProjectDataflow using CloudSQL Public IP
STATUS: Success

请分享您从另一个项目访问 Cloud SQL 的经验。
是否有从另一个 gcp 项目连接云 SQL 的最佳实践?

最佳答案

编辑:

较新的实例似乎默认启用了此选项,并且不再需要联系支持人员。但是,如果在所有过程之后,设置仍然无法正常工作,则可能需要联系支持人员。

重要提示:VPC 对等选项将不再起作用,如文档中所述,更准确地说是在 Considerations topic 中。 .那么实现它的唯一可用选项是使用共享 VPC

将 Cloud SQL 与另一个 GCP 项目互连的过程非常简单,遵循 documentation .为了使其正常工作,您需要考虑的唯一一件事是,您必须请求 Google Cloud 支持为您的 Cloud SQL 散斑伞实例启用自定义路由,您的 Cloud SQL 在其中运行,否则您将不会能够在您的 GCP 项目中访问您的 Cloud SQL。

以下步骤将为您工作:

-为 Cloud SQL 实例配置 VPC

Inside the project where you have your Cloud SQL instance, create a VPC network with the ip address range of your desire. Choose the same zone for the VPC in which your instance is located.



-为 GCP 项目配置 VPC

Now switch to the project where your CloudDataflow instance is located and follow the same process. Create the VPC network being careful that the IP ranges do not collide between each other. You can use the following tool to check if the IP addresses range collide. Also take into consideration that both VPC networks must be in the same zone.



-通过对等连接两个项目的 VPC

Once both VPC networks are created it is needed to configure the VPC network peering from both projects. From the Cloud SQL instance side, configure the peering specifying the project and VPC network name to connect with and also select the option to export custom routes. This way the other part of the peering, in this case your GCP project, will have visibility of your Cloud SQL instance. Now, from the GCP project side, configure the peering specifying the Cloud SQL project name and the VPC network name to connect with. The same way we did with the Cloud SQL peering, we have to set up the peering to import custom routes as it will receive exported routes coming from the other side of the connection, which in our case is your Cloud SQL instance.



Here您可以查看有关在任何 VPC 网络对等互连之间导入和导出路由的更多信息。

-请求 Google Cloud 支持为您启用 Cloud SQL 的交换自定义路由

Reach Google Cloud Support and ask them to enable the exchange of custom routes for your speckle-umbrella VPC network associated with your instance that is automatically created upon the Cloud SQL instance is created.



考虑到这最后一步非常重要,所有 SQL 项目都在伞形项目下运行,因此如果不请求 Google Cloud Support 为您的实例启用交换自定义路由,这将永远无法工作。

共享 VPC

至于共享 VPC,您唯一需要考虑的是,您需要在创建 Cloud SQL 实例后启用该选项,因为之后您无法添加它。

您将在以下 link 中找到共享 VPC 的配置指南.

关于google-cloud-platform - 从另一个 GCP 项目访问 Cloud SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56742056/

相关文章:

node.js - chromeos 上的 ssh 隧道连接被拒绝

google-kubernetes-engine - 与 Google Container Engine 共享 VPC 网络

firebase - 如何将数据从 Pub/Sub 发送到 Google Cloud Firestore?

java - 定义 Cloud SQL 的 root 密码是否会干扰 AppEngine 上运行的应用程序的连接?

postgresql - pg_stat_statements_reset() 权限在 Google Cloud SQL PostgreSQL 上被拒绝

networking - 从 GCE 中的旧网络迁移

ssl - 正在处理 gke 证书管理器证书

firebase - 我怎么知道谁更改了我的 Cloud Function

python - 从 python 列表的值向 google BigQuery 表插入一行

google-cloud-platform - 有没有办法通过docker容器内的代理访问谷歌云SQL