[英]Connecting to Cloud SQL private IP from GCE VM application
I am checking Cloud SQL Private IP connections from different types of clients. 我正在检查来自不同类型客户端的Cloud SQL专用IP连接。 I could successfully make a connection from an application hosted in a GKE cluster which was created as a VPC-native cluster as described here .
我可以顺利地从在描述这是一个VPC-本地集群创造了GKE集群托管的应用程序的连接在这里 。 Having already done this, I was expecting it would be easier to connect to the Private IP from the same application (which is a simple Spring Boot application) hosted in a GCE VM.
完成此操作后,我期望从GCE VM中托管的同一应用程序(这是一个简单的Spring Boot应用程序)连接到私有IP会更容易。 Contrary to my expectations this does not appear to be so.
与我的期望相反,事实并非如此。 It is the same Spring Boot application that I am trying to run inside a VM.
这是我尝试在VM内运行的同一Spring Boot应用程序。 But it does not seem to be able to connect to the database.
但是它似乎无法连接到数据库。 I was expecting some connection error but nothing shows up - no exception thrown.
我期待一些连接错误,但是什么都没有出现-没有抛出异常。 What is strange is I am able connect to the Cloud SQL Private IP via
mysql
command line from the same VM but not from within the Spring Boot application. 奇怪的是我能够通过
mysql
命令行从同一VM连接到Cloud SQL Private IP,但不能从Spring Boot应用程序内部连接到Cloud SQL Private IP。 Anyone out there who faced this before? 有人以前遇到过这个吗?
Issue was not related Cloud SQL Private IP. 问题与Cloud SQL专用IP不相关。 As mentioned in my earlier comment, I was passing active profile info via Kubernetes pod configuration.
如我先前的评论中所述,我正在通过Kubernetes pod配置传递活动的配置文件信息。 So the Dockerfile did not have this info.
因此,Dockerfile没有此信息。 To fix the issue, I had to pass active profile info when the program was initialized outside Kubernetes.
为了解决这个问题,当程序在Kubernetes外部初始化时,我必须传递活动的配置文件信息。 This has a lot of helpful answers how to do this.
如何执行此操作有很多有用的答案。 If the program is being started via a
docker run
command the active profile info can be passed as a command line argument. 如果通过
docker run
命令启动程序,则可以将活动配置文件信息作为命令行参数传递。 See here for a useful reference. 请参阅此处以获取有用的参考。
So to summarize, Cloud SQL Private IP works fine from a CE VM. 综上所述,Cloud SQL Private IP可从CE VM正常运行。 No special configuration required at GCE VM end to get this working.
在GCE VM端不需要特殊配置即可使此工作正常进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.