问题描述
我正在按照 Google Cloud Platform 的指南使用 Cloud sql 代理和公共 IP 地址 (https://cloud.google.com/sql/docs/postgres/connect-kubernetes-engine) 通过 GKE 集群连接到 Cloud sql 实例。但是,在尝试部署我的应用程序后,我的容器日志中出现以下错误。
{ Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
errno: 'ECONNREFUSED',code: 'ECONNREFUSED',syscall: 'connect',address: '127.0.0.1',port: 5432 }
后跟错误信息
2021/02/01 05:35:31 the default Compute Engine service account is not configured with sufficient permissions to access the Cloud sql API from this VM. Please create a new VM with Cloud sql access (scope) enabled under "Identity and API access". Alternatively,create a new "service account key" and specify it using the -credential_file parameter
此外(我假设相关)当我检查集群中节点的计算引擎时,我看到 Cloud sql Cloud API 访问范围被禁用。有没有办法启用它?
我知道有多种方法可以通过 GKE 集群连接到 Cloud sql 实例,但是,我想通过凭据文件使用工作负载标识。
解决方法
如果您不在 Compute Engine 虚拟机上使用默认服务帐号,则无需使用虚拟机的范围。范围仅对 Compute 引擎默认服务帐户强制执行,对于自定义服务帐户则不强制执行。
如果您在集群上使用工作负载身份,则情况相同(因为使用的不是 Compute Engine 默认服务帐户,而是自定义服务帐户)。是的,比服务帐户密钥文件更喜欢这个。