Connecting with Cloud SQL Proxy
It is possible to connect to iterapp instances using Cloud SQL Proxy. It provides a secure connection and easier connection management (according to the documentation). An in-depth explanation can be found here and the installation can be found here.
After installation, credentials must be set up with gcloud to gain access to the
iterapp instances which can be installed following this
link. When gcloud is installed, start up
the Cloud SDK Shell and run gcloud init
. The Cloud SDK Shell will prompt a
login where you use your iterate mail. When logged in, choose app-iterate
as
your cloud project and run gcloud auth application-default login
on the SDK
Shell (which might prompt a new login) this will set the chosen account to be
your default auth credentials for the SQL Proxy.
Now that the credentials are set, run the cloud_sql_proxy
executable again
with the following command:
./cloud-sql-proxy app-iterate:europe-west1:app-iterate --port 5432
. With this
up and running, open up a new command line tab and connect to your chosen
instance. For example, when connecting to a postgres database you can type the
following command on the new command line tab:
psql -u myInstanceUser --host 127.0.0.1 --port 5432
.
One important thing to note here is the port number that is being used to run
the Cloud SQL Proxy. You might not be able to connect to instances if the port
is already being used. With the example of connecting to a postgres database you
might get connection errors if you already have a local postgres database
running. This can be fixed by running the Cloud SQL Proxy on a different port
like so
./cloud-sql-proxy app-iterate:europe-west1:app-iterate --port 5433
and connecting to the database on that port
psql -u myInstanceUser --host 127.0.0.1 --port 5433
.
Upgrading Google Cloud CLI (for example from 372.0.0 to 382.0.0 might break the cloud proxy script.
Following step 1 and 2 here https://cloud.google.com/sql/docs/mysql/connect-admin-proxy might fix that.