How do I connect to the database on Cloud SQL without having to add my credentials file inside the container?
Steren
UPDATE: to connect to Cloud SQL from Cloud Run see the official documentation
Cloud SQL is now supported by the fully managed version of Cloud Run (Cloud Run on GKE users were already able to use Cloud SQL using a private IP)
The feature is currently in alpha, so you need to use gcloud alpha
(it will be in gcloud beta
within 10 days):
To get started:
- if you do not have one already, create a Cloud SQL instance.
- make sure that the Cloud SQL admin API
- deploy a new revision of your Cloud Run service with gcloud alpha and the following flag:
$ gcloud alpha run services update --add-cloudsql-instances [INSTANCE_CONNECTION_NAME]
Where isINSTANCE_CONNECTION_NAME
is of the typeproject:region:instancename
.
When yo do this, Cloud Run will activate and configure the Cloud SQL proxy for you. You should then connect to it via the /cloudsql/[INSTANCE_CONNECTION_NAME]
Unix socket.
来源:https://stackoverflow.com/questions/55693241/how-to-securely-connect-to-cloud-sql-from-cloud-run