简体   繁体   English

无法通过具有 Workload Identity 的 GKE 连接到 Cloud SQL 代理

[英]Cannot connect to Cloud SQL Proxy through GKE with Workload Identity

I am following the Google Cloud Platform's guide for connecting to a Cloud SQL instance through a GKE cluster using Cloud SQL Proxy and a Public IP address ( https://cloud.google.com/sql/docs/postgres/connect-kubernetes-engine ). I am following the Google Cloud Platform's guide for connecting to a Cloud SQL instance through a GKE cluster using Cloud SQL Proxy and a Public IP address ( https://cloud.google.com/sql/docs/postgres/connect-kubernetes-engine )。 However, after trying to deploy my application I get the following error in my container logs.但是,在尝试部署我的应用程序后,我的容器日志中出现以下错误。

{ 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 }

Followed by the error message其次是错误信息

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

In addition (and I assume related) when I check my compute engine for the node in the cluster I see that the Cloud SQL Cloud API access scope is disabled.此外(我假设相关)当我检查集群中节点的计算引擎时,我看到云 SQL 云 API 访问 scope 被禁用。 Is there a way to enable this?有没有办法启用它?

I am aware that there are multiple ways to connect to a Cloud SQL Instance through a GKE cluster, however, I would like to use workload identity over a credentials file.我知道有多种方法可以通过 GKE 集群连接到 Cloud SQL 实例,但是,我想通过凭证文件使用工作负载身份。

I've faced the similar exception while following the guide Connect to Cloud SQL for MySQL from Google Kubernetes Engine在遵循Google Kubernetes 引擎的 MySQL 的指南连接到云 SQL时,我遇到了类似的异常

Finally, it has turned out, that Workload Identity was not enabled fully on my Kubernetes cluster.最后,事实证明,我的 Kubernetes 集群上没有完全启用 Workload Identity。 So, in case of using Workload Identity approach, you should ensure:因此,如果使用 Workload Identity 方法,您应该确保:

  1. Workload Identity is enabled in your cluster settings . Workload Identity 在您的集群设置中启用。 This was turned on in my case.在我的情况下,这是打开的。

  2. Your node pool is also updated to use Workload Identity.您的节点池也已更新为使用 Workload Identity。 If not, execute the following:如果没有,请执行以下操作:

gcloud container node-pools update NODEPOOL_NAME \
    --cluster=CLUSTER_NAME \
    --zone=YOUR_CLUSTER_ZONE or --region=YOUR_CLUSTER_REGION \
    --workload-metadata=GKE_METADATA

After these steps my gke-sql deployment became green.在这些步骤之后,我的 gke-sql 部署变为绿色。

If you don't use the default service account on your Compute Engine VM, you don't need to play with the scope of the VM.如果您不在 Compute Engine 虚拟机上使用默认服务帐户,则无需使用虚拟机的 scope。 The scope are enforced only with the Compute engine default service account, with custom service account, they aren't. scope 仅使用计算引擎默认服务帐户强制执行,使用自定义服务帐户,它们不是。

If you use Workload identity on your cluster, it's the same thing (because it's not the Compute Engine default service account which is used but a custom one).如果您在集群上使用工作负载身份,则情况相同(因为使用的不是 Compute Engine 默认服务帐户,而是自定义服务帐户)。 And yes prefer this to Service Account key file.是的,比服务帐户密钥文件更喜欢这个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于将 GKE 集群连接到不同 GCP 项目的工作负载身份 - Workload identity to connect a GKE cluster to a different GCP project GKE 工作负载身份池 VS 来自工作负载身份联合的工作负载身份池 - GKE workload identity pool VS workload identity pools from workload identity federation 在现有 gke 和 nodepool 中启用“工作负载标识”是否有任何停机时间? - Does enabling "workload identity" in an existing gke and nodepool has any downtime? 如何使用 Python 和私有 IP 从 GKE 连接到 Cloud SQL - How to connect from GKE to Cloud SQL using Python and Private IP 在 GKE (.NET) 中使用 Workload Identity 时无法获取访问令牌 - Unable to get access token when using Workload Identity in GKE (.NET) 使用 GKE 中的工作负载身份访问服务帐户密钥 json - Access Service Account key json using workload identity in GKE 从 GKE pod 查询 Node.js 中的 Google 云 SQL 实例,云 sql 代理作为边车运行 - Query a Google cloud SQL instance in Node.js from a GKE pod with cloud sql proxy running as sidecar 无法将云 function 连接到云 SQL - Cannot connect cloud function to Cloud SQL 为什么在端口转发到代理且服务有效时,其他 Pod 无法通过 Kubernetes 代理和服务连接到 Cloud SQL? - Why can't other pods connect to Cloud SQL through Kubernetes proxy and service when portforwarding to the proxy and the service works? 使用 Workload Identity 在 Kube.netes 上的 Cloud ML Engine 中的容器中验证独立 gsutil - Authenticating standalone gsutil in containers in Cloud ML Engine on Kubernetes with Workload Identity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM