我想通过 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 来允许所有连接到数据库。我还尝试添加防火墙规则。两者都没有成功。
1 回答
炎炎设计
TA贡献1808条经验 获得超4个赞
当前的建议是使用 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
添加回答
举报
0/150
提交
取消