How to connect from a pool of Google Compute Engine instances to Cloud SQL DB in the same project?

心已入冬 提交于 2020-01-03 02:55:10

问题


If I have a pool of Compute Engine instances (behind a load-balancer with a static IP), and I want to connect from Java apps on these instances to a Cloud Sql database in the same project, what's the way to about it?

1) These instances in the load balancer don't have static external IPs, so I can't authorize access to Cloud SQL by IP addresses.

2) "com.mysql.jdbc.GoogleDriver" is not available on Compute Engine, as it is on App Engine.

3) If I try to use the stock MySql JDBC driver, it doesn't understand a connection string like:

"jdbc:google:mysql://__instance_name__/__db_name__>?user=__user__&password=__password__";

and fails saying "No suitable driver found for jdbc:google:mysql://__instance_name__/__db_name__>?user=__user__&password=__password__"

I can't believe I can't easily connect from Compute Engine instances to a Cloud SQL database of the same Google Cloud project.

Is my only option to use "Connecting using the Cloud SQL Proxy" approach as described on https://cloud.google.com/sql/docs/compute-engine-access? That seems significant amount of work to be done automatically on instances that will come to the pool and go away at will!

Could someone please throw some light on it?

Thanks.


回答1:


Finally able to connect from dynamic-IP GCE instances to Google Cloud SQL database through the Google Cloud Sql proxy. Since there were variants (same-project-app-to-db, different-project-app-to-db) and I also wanted to keep some App-engine-to-Cloud-SQL connection information nearby for anyone who may need it, made a little write-up about it and put it at https://roshandawrani.wordpress.com/2016/09/22/connecting-from-gce-gae-java-to-google-cloud-sql/. Hope it's ok to leave the link here to the detailed information instead of reproducing everything here again. Cheers.



来源:https://stackoverflow.com/questions/39624332/how-to-connect-from-a-pool-of-google-compute-engine-instances-to-cloud-sql-db-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!