问题描述
如何在不将我的凭据文件添加到容器内的情况下连接到Cloud SQL上的数据库?
How do I connect to the database on Cloud SQL without having to add my credentials file inside the container?
推荐答案
更新:要从Cloud Run连接到Cloud SQL,请参见官方文档
UPDATE: to connect to Cloud SQL from Cloud Run see the official documentation
Cloud Run的完全托管版本现在支持Cloud SQL(GKE用户上的Cloud Run已经能够使用私有IP使用Cloud SQL)
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)
开始使用:
- 如果您还没有一个,请创建Cloud SQL实例.
- 确保 Cloud SQL管理API 为已启用
- 使用gcloud alpha和以下标志部署您的Cloud Run服务的新修订版:
$ gcloud run services update --add-cloudsql-instances [INSTANCE_CONNECTION_NAME]
INSTANCE_CONNECTION_NAME
的位置为project:region:instancename
类型.
- if you do not have one already, create a Cloud SQL instance.
- make sure that the Cloud SQL admin API is enabled
- deploy a new revision of your Cloud Run service with gcloud alpha and the following flag:
$ gcloud run services update --add-cloudsql-instances [INSTANCE_CONNECTION_NAME]
Where isINSTANCE_CONNECTION_NAME
is of the typeproject:region:instancename
.
执行此操作时,Cloud Run将激活并配置 Cloud SQL代理.然后,您应该通过/cloudsql/[INSTANCE_CONNECTION_NAME]
Unix套接字连接到它.
When you 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.
这篇关于如何从Cloud Run安全地连接到Cloud SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!