【问题标题】:GCloud - Can't access Cloud SQL from Kubernetes Cluster but it works from local PCGCloud - 无法从 Kubernetes 集群访问 Cloud SQL,但它可以在本地 PC 上运行
【发布时间】:2018-09-27 07:05:40
【问题描述】:

我想通过 JDBC 从运行在 GCloud Kubernetes Engine 中的容器连接到我的 Cloud SQL 数据库 (MySQL)。该容器包含一个带有一些 REST 服务的 Java Spring Boot 应用程序。

当我在本地运行我的 Java 应用程序时,一切正常,并且应用程序连接到 Cloud SQL DB 也很好。但是,当我将应用程序部署到 GCloud 时,只有在调用服务器 REST API(通过 Postman)时才会收到此响应:

{
"timestamp": "2018-09-27T06:54:22.987+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Could not open JDBC Connection for transaction; nested exception 
is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications 
link failure\n\nThe last packet sent successfully to the server was 0 
milliseconds ago. The driver has not received any packets from the server.",
"path": "/api/user/getDbs"
}

我已经尝试通过在授权选项卡中添加 0.0.0.0/0 来允许与数据库的所有连接。 我还尝试添加防火墙规则。两者都没有成功。

感谢任何帮助,我可以得到:)

【问题讨论】:

    标签: java google-cloud-sql google-kubernetes-engine


    【解决方案1】:

    目前的建议是使用 cloud-sql-proxy 运行 sidecar 容器。这里有一篇很好的文章 (https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine)。还有一个看起来很有希望的测试服务代理。您不需要使用代理授权或导入证书。但是,请确保提供的服务帐户具有正确的连接权限。之后,您的应用可以连接到 localhost:POR

    https://cloud.google.com/kubernetes-engine/docs/concepts/google-cloud-platform-service-broker

    【讨论】:

      猜你喜欢
      • 2018-09-05
      • 2022-07-14
      • 2018-10-13
      • 2021-11-23
      • 2023-03-09
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多