Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to connect to Google Cloud SQL from a Google Managed VM?

Is it possible to connect to Google Cloud SQL from a Google Managed VM? With regular Google App Engine applications, I can connect by authorizing my project in the Cloud SQL console and using unix_socket='/cloudsql/' + _INSTANCE_NAME. However, the /cloudsql/ socket doesn't seem to be available on Managed VMs. Do I have to whitelist the IP of my Managed VM application? If so, how do I find the IP address to whitelist?

like image 510
AJH Avatar asked Mar 18 '23 13:03

AJH


1 Answers

The /cloudsql/ sockets are only available in regular App Engine. Managed VMs are regular VMs so connection to Cloud SQL needs to use the external IP of that Cloud SQL instances. The external IP needs to be whitelisted. The external IP is showed in the Developers Console and can also be retrieved via gcloud CLI tool.

Two options to avoid having to whitelist the IP of the GCE VMs are:

  1. Switch to use only SSL connections for IP connectivity and whitelist 0.0.0.0/0.
  2. Funnel all the traffic to Cloud SQL via a VM that runs a TCP proxy (HAProxy) for example.

We are aware that none of these are very satisfying solutions. :-(

like image 177
Razvan Musaloiu-E. Avatar answered Apr 10 '23 09:04

Razvan Musaloiu-E.