简体   繁体   English

启用私有 IP 并关闭公共 IP 后无法从 Cloud Run 连接到 Cloud SQL

[英]Cannot connect to Cloud SQL from Cloud Run after enabling private IP and turning off public iP

I have a postgreSQL CLoud SQL instance which I am connecting to via UNIX socket and the instance name from a Cloud Run container as per the documentation.我有一个 postgreSQL CLoud SQL 实例,我通过 UNIX 套接字连接到它,并且根据文档从 Cloud Run 容器中获取实例名称。 With a public IP, this connection works fine.使用公共 IP,此连接工作正常。 I was looking to turn off the public IP and only have a private IP, so I would not be charged for the public IP going forward.我想关闭公共 IP 并且只有一个私有 IP,所以我不会为以后的公共 IP 付费。

When I first created the Cloud SQL instance, I only enabled the public IP.当我第一次创建 Cloud SQL 实例时,我只启用了公共 IP。 A couple of days later I enabled the private IP.几天后,我启用了私有 IP。 For the assocaited network for the private IP, I accepted the default as the Cloud Run instance is in the same project.对于私有 IP 的关联网络,我接受了默认值,因为 Cloud Run 实例在同一个项目中。

When I turn off the public IP, my application can no longer connect to the Cloud SQL instance.当我关闭公共 IP 时,我的应用程序无法再连接到 Cloud SQL 实例。 I get a connection refused error:我收到连接拒绝错误:

sqlalchemy.exc.InterfaceError: (pg8000.core.InterfaceError) ('communication error', ConnectionRefusedError(111, 'Connection refused'))

As stated above, I did follow the instruaction on the Connecting to Cloud SQL from Cloud Run page:如上所述,我确实遵循了从 Cloud Run 连接到 Cloud SQL 页面上的说明:

https://cloud.google.com/sql/docs/postgres/connect-run https://cloud.google.com/sql/docs/postgres/connect-run

I even ran the gcloud command to update an the exsiting deployed revision after turning off the public IP and only having the private IP available but it made no difference.在关闭公共 IP 并且只有私有 IP 可用后,我什至运行 gcloud 命令来更新现有部署的修订版,但没有任何区别。

Is a public IP required for a connection from Cloud Run to Cloud SQL?从 Cloud Run 连接到 Cloud SQL 是否需要公共 IP? I do not see that in the connection documentation page.我在连接文档页面中没有看到。 Or is there something else I missed when trying to switch over to only having a private IP?或者在尝试切换到仅拥有私有 IP 时我还错过了什么? Or do I need to create a new Cloud Instance without a public IP and go through the instructions for connecting Cloud Run via an instance anme again?或者我是否需要创建一个没有公共 IP 的新 Cloud 实例,然后再次按照通过实例名称连接 Cloud Run 的说明进行操作?

Is a public IP required for a connection from Cloud Run to Cloud SQL?从 Cloud Run 连接到 Cloud SQL 是否需要公共 IP? I do not see that in the connection documentation page.我在连接文档页面中没有看到。

On the Connecting to Cloud SQL from Cloud Run page , it says "Note: These instructions require your Cloud SQL instance to have a public IP address configured."从 Cloud Run 连接到 Cloud SQL 页面上,它显示“注意:这些说明要求您的 Cloud SQL 实例配置公共 IP 地址。”

Private IP access is access from a Virtual Private Cloud (VPC) .私有 IP 访问是从虚拟私有云 (VPC) 访问 In order to access your instance through a VPC, the resource you are connecting to needs to be a part of the VPC.为了通过 VPC 访问您的实例,您要连接的资源需要是 VPC 的一部分。 Cloud Run doesn't currently support VPC access, so you'll need to use have a public IP for now. Cloud Run 目前不支持 VPC 访问,因此您现在需要使用公共 IP。

TL;DR : Open a case to the Google support TL;DR : 向 Google 支持开立案例

Your case is interesting because, by design, I think it's not yet supported.您的案例很有趣,因为根据设计,我认为它还不受支持。

In fact, when you create a Cloud SQL database with a private IP, a network peering is done between your VPC and the Cloud SQL VPC (or something equivalent) .事实上,当您使用私有 IP 创建 Cloud SQL 数据库时,您的 VPC 和 Cloud SQL VPC(或类似的东西)之间会建立网络对等互连

In addition, today, it's not possible to plug your Cloud Run instance to your VPC.此外,今天无法将您的 Cloud Run 实例插入到您的 VPC。 With function and App Engine, you have a serverless VPC connector , and not yet with Cloud Run (it's coming!).有了函数和 App Engine,您就有了无服务器 VPC 连接器,而 Cloud Run 还没有(即将推出!)。

The serverless VPC connector perform the same things as the Cloud SQL private IP, I mean a peering between your VPC and the Cloud Functions (or App Engine) VPC (or something equivalent).无服务器 VPC 连接器执行与 Cloud SQL 私有 IP 相同的功能,我的意思是您的 VPC 和 Cloud Functions(或 App Engine)VPC(或等效的东西)之间的对等互连。

And even if the serverless VPC connector is available on Cloud Run, it's not sure that it work because of network peering transitivity .即使 Cloud Run 上提供无服务器 VPC 连接器,由于网络对等传输性,也不确定它是否有效。 In short, If you have a peering between VPC A -> VPC B and between VPC B -> VPC C, you can't reach VPC C from VPC A by performing an hop in VPC B. Replace A by VPC Cloud Run, B by VPC of your project, and C by VPC Cloud SQL.简而言之,如果您在 VPC A -> VPC B 和 VPC B -> VPC C 之间有对等互连,则无法通过在 VPC B 中执行跳跃从 VPC A 到达 VPC C。将 A 替换为 VPC Cloud Run, B由您项目的 VPC 和 C 由 VPC Cloud SQL。

Only directly peered networks can communicate.只有直接对等互连的网络才能进行通信。 Transitive peering is not supported.不支持传递对等互连。 In other words, if VPC network N1 is peered with N2 and N3, but N2 and N3 are not directly connected, VPC network N2 cannot communicate with VPC network N3 over VPC Network Peering.换句话说,如果VPC网络N1与N2和N3对等,但N2和N3没有直接连接,则VPC网络N2无法通过VPC网络对等连接与VPC网络N3通信。

I didn't check with AppEngine or Cloud Function, but this design shouldn't work.我没有检查 AppEngine 或 Cloud Function,但这种设计应该不起作用。

But I'm not sure, that's why a case to the Google support will allow you to have a clear answer and maybe inputs on the roadmap.但我不确定,这就是为什么给 Google 支持的案例可以让您有明确的答案,并且可能会在路线图上提供输入。 Any valuable information from Google Support are welcomed here!欢迎在此处提供来自 Google 支持的任何有价值的信息!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法通过云运行连接到云 sql 私有 IP - not able to connect to cloud sql private IP via cloud run 无法使用私有 IP 从 Cloud Functions 连接到 Cloud SQL SQL Server - Cannot connect to Cloud SQL SQL Server from Cloud Functions using private IP 从具有私有和公共 IP 的虚拟机连接到私有 IP 上的 Google Cloud SQL 实例失败 - Connecting to Google Cloud SQL instance on private IP from a VM with both private and public IPs fails 如何从我的电脑连接到谷歌云平台中私有 ip 的 sql 实例 - How to connect from my pc to sql instance with private ip in google cloud platform 使用私有 IP 从不同 VPC 网络中的 GKE 集群连接到云 SQL - Connect to Cloud SQL from GKE clusters in different VPC Networks using Private IP GCP 使用 VM 通过 Cloud SQL Auth Proxy Private IP 连接到 Cloud SQL - GCP using VM to connect to Cloud SQL via Cloud SQL Auth Proxy Private IP 通过GCE或GKE使用私有IP连接到Cloud SQL - Connecting to Cloud SQL with Private IP from GCE or GKE 从GCE VM应用程序连接到Cloud SQL专用IP - Connecting to Cloud SQL private IP from GCE VM application 无法通过 Google Cloud Shell 中的云 sql 代理使用私有 IP 进行连接 - - Not able to connect using private IP via cloud sql proxy in Google Cloud Shell - Cloud Sql Proxy 私有IP 外部应用 - Cloud Sql Proxy Private IP External application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM