GCloud - 无法从 Kubernetes 集群访问云 SQL,但它可以在本地 PC 上运行
GCloud - Can't access Cloud SQL from Kubernetes Cluster but it works from local PC
我想通过 JDBC 从 GCloud Kubernetes Engine 中的容器 运行ning 连接到我的云 SQL 数据库 (MySQL)。该容器包含一个 Java Spring 带有一些 REST 服务的引导应用程序。
当我在本地 运行 我的 Java 应用程序时,一切正常,应用程序连接到云 SQL 数据库也很好。但是,当我将我的应用程序部署到 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 来允许与数据库的所有连接。
我还尝试添加防火墙规则。两者都没有成功。
感谢任何帮助,我可以得到:)
目前的建议是 运行 带有云-sql-代理的边车容器。这里有一篇很好的文章 (https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine)。还有一个似乎很有前途的 beta 服务代理。您不需要使用代理授权或导入证书。但是,请确保提供的服务帐户具有正确的连接权限。之后,您的应用程序可以在 localhost:POR
上连接
https://cloud.google.com/kubernetes-engine/docs/concepts/google-cloud-platform-service-broker
我想通过 JDBC 从 GCloud Kubernetes Engine 中的容器 运行ning 连接到我的云 SQL 数据库 (MySQL)。该容器包含一个 Java Spring 带有一些 REST 服务的引导应用程序。
当我在本地 运行 我的 Java 应用程序时,一切正常,应用程序连接到云 SQL 数据库也很好。但是,当我将我的应用程序部署到 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 来允许与数据库的所有连接。 我还尝试添加防火墙规则。两者都没有成功。
感谢任何帮助,我可以得到:)
目前的建议是 运行 带有云-sql-代理的边车容器。这里有一篇很好的文章 (https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine)。还有一个似乎很有前途的 beta 服务代理。您不需要使用代理授权或导入证书。但是,请确保提供的服务帐户具有正确的连接权限。之后,您的应用程序可以在 localhost:POR
上连接https://cloud.google.com/kubernetes-engine/docs/concepts/google-cloud-platform-service-broker