I want to connect to my Cloud SQL Database (MySQL) from a container running in the GCloud Kubernetes Engine via JDBC. The container contains a Java Spring Boot application with some REST services.
When I run my Java application locally, everything works fine and the application connects to the Cloud SQL DB just fine. However when I deploy my app to the GCloud, I only get this response, when I call my server REST API (via 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"
}
I already tried to allow all connections to the Database, via adding 0.0.0.0/0 in the authorization tab. I also tried to add firewall rules. Both without any success.
I appreciate any help, I can get :)
Current recommendation is to run a sidecar container with cloud-sql-proxy. There is a nice write up here (https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine). There is also a beta service broker which seems promising. You do not need to authorize or import certs with the proxy. However, be sure the service account provided has the correct permissions to connect. Afterwards, your app can connect on localhost:POR
https://cloud.google.com/kubernetes-engine/docs/concepts/google-cloud-platform-service-broker