【问题标题】:Not able to connect to SQL in Google Cloud无法连接到 Google Cloud 中的 SQL
【发布时间】:2019-07-18 00:08:06
【问题描述】:

我无法在 GCP 中连接到 Cloud SQL, 我的 Spring Boot 应用程序托管在 Google Kubernetes 中, 我能够将我的应用程序从本地连接到数据库 但是当我在 kubernetes 中部署我的应用程序映像时它不起作用 我检查了日志并得到了这个

{
insertId:  "s=5ae000c9c858402ba514b2f9a2a7d34d;i=557f;    b=fef2848a05ed422b811cda756eea59d6;m=2a5164d50;t=58dde1640752b;  x=4a97c620c9fbf136-0@aa"  
logName:  "projects/finomatic  /logs/cloudsql.googleapis.com%2Fmysql.err"  
receiveTimestamp:  "2019-07-17T10:38:04.977705316Z"  
resource: {…}  
severity:  "INFO"  
textPayload:  "2019-07-17T10:37:59.135897Z 1340 [Note] Aborted  connection 1340 to db: 'finomatic' user: 'root' host: '  cloudsqlproxy~129.41.84.82' (Got an error reading communication packets)"  
timestamp:  "2019-07-17T10:37:59.136950Z"  
}

所以我在 sql Connection 选项卡中添加了我的集群 IP,但仍然收到此错误 当我只是预览我的应用程序泊坞窗图像时,我的 API 工作正常 部署后 api 不起作用 部署后出现此错误 Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection

【问题讨论】:

    标签: sql kubernetes google-cloud-platform


    【解决方案1】:

    尽管您已在 Cloud SQL 中将您的客户端 IP 列入白名单,GKE has masquerading active 表示,所有出站互联网连接都将被 NAT 到节点的外部地址。

    ip-masq-agent 配置 iptables 规则以在向节点和集群 IP 范围之外的目的地发送流量时处理伪装节点/Pod IP 地址。 Pod IP 地址隐藏在其节点地址后面。

    还有来自 GKE 的 couple of ways to connect to Cloud SQL。在我看来,最直接的方法是在您的 pod 中使用 Cloud SQL Proxy deployed as a sidecar container

    如果代理不是一个选项,您可以调整 IP masquerade agent 以绕过此 SNAT 规则并保留请求的源 IP。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 1970-01-01
      • 2019-11-10
      • 2015-12-18
      • 2021-03-27
      • 2021-08-10
      • 2020-09-25
      相关资源
      最近更新 更多