Ho 为 Google Cloud SQL Postgresql 实例建立连接 URL
Ho to build Connection URL for Google Cloud SQL Postgresql Instance
我想将我的应用程序连接到 google 云 SQL 上的托管 postgresql 实例。该应用程序将通过 GKE 部署。通常,我会通过连接字符串进行连接:
例如:postgres://<user>:<password>@<my-postgres-host>:5432"
但是 documentation 指出:
创建一个 Secret 以向数据库提供 PostgreSQL 用户名和密码。
使用以下项目更新您的 pod 配置文件:
- 提供云 SQL 实例的私有 IP 地址作为您的应用程序将用于访问数据库的主机地址。
- 提供您之前创建的 Secret,使应用程序能够登录数据库。
- 使用 Kubernetes 清单文件启动您的 Deployment。
我可以执行第 1 步和第 3 步,但无法执行第 2 步。如果连接 URL 只是:postgres://<PRIVATE_ID>:5432
并且我添加 ENV 变量 POSTGRES_USER
和 POSTGRES_PASSWORD
通过秘密?
有没有我可以查的例子?
结果: 我想为托管在 google 云 sql 上的 postgresql 导出连接 url .
提前致谢!
您可以找到 postgres_deployment.yaml 文件的示例,以使用 kubernetes 进行部署。示例用户代理,但数据库配置部分不会因私有 IP 而更改。对于私有 IP,请勿使用 [proxy_container]
部分
这是文档中所述的部分,您正在搜索:数据库环境变量和机密部分。
# The following environment variables will contain the database host,
# user and password to connect to the PostgreSQL instance.
env:
- name: POSTGRES_DB_HOST
value: 127.0.0.1:5432
# [START cloudsql_secrets]
- name: POSTGRES_DB_USER
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: username
- name: POSTGRES_DB_PASSWORD
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: password
# [END cloudsql_secrets]
我想将我的应用程序连接到 google 云 SQL 上的托管 postgresql 实例。该应用程序将通过 GKE 部署。通常,我会通过连接字符串进行连接:
例如:postgres://<user>:<password>@<my-postgres-host>:5432"
但是 documentation 指出:
创建一个 Secret 以向数据库提供 PostgreSQL 用户名和密码。
使用以下项目更新您的 pod 配置文件:
- 提供云 SQL 实例的私有 IP 地址作为您的应用程序将用于访问数据库的主机地址。
- 提供您之前创建的 Secret,使应用程序能够登录数据库。
- 使用 Kubernetes 清单文件启动您的 Deployment。
我可以执行第 1 步和第 3 步,但无法执行第 2 步。如果连接 URL 只是:postgres://<PRIVATE_ID>:5432
并且我添加 ENV 变量 POSTGRES_USER
和 POSTGRES_PASSWORD
通过秘密?
有没有我可以查的例子?
结果: 我想为托管在 google 云 sql 上的 postgresql 导出连接 url .
提前致谢!
您可以找到 postgres_deployment.yaml 文件的示例,以使用 kubernetes 进行部署。示例用户代理,但数据库配置部分不会因私有 IP 而更改。对于私有 IP,请勿使用 [proxy_container]
部分这是文档中所述的部分,您正在搜索:数据库环境变量和机密部分。
# The following environment variables will contain the database host,
# user and password to connect to the PostgreSQL instance.
env:
- name: POSTGRES_DB_HOST
value: 127.0.0.1:5432
# [START cloudsql_secrets]
- name: POSTGRES_DB_USER
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: username
- name: POSTGRES_DB_PASSWORD
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: password
# [END cloudsql_secrets]