Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Connecting from a process running in GKE cluster to postgresql (Cloudsql)

hello,

I am trying to connect from my GKE cluster to postgresql instance (cloudsql) and i am getting this error.

 

Creating database xxxxx on companyname@10.XX.XX.XX:5432 psql: could not connect to server: Operation timed out Is the server running on host "10.XX.XX.XX" and accepting TCP/IP connections on port 5432?

 

Any suggestion on why this is?

0 3 434
3 REPLIES 3

Are your GKE cluster and Cloud SQL instance on the same project?

Yes, they are. Are in thesame region.

If the connection is being rejected by the instance, it could mean the cluster’s IP address is not on the authorized network list.

Another possible root cause for no connectivity is that your cluster has no VPC-native traffic routing enabled.

If you want to use the private IP address, you need to create a new GKE cluster VPC-native-cluster to enable “VPC-native traffic routing” following the next documentation [1], [2]. 

I would also like to mention that, as an alternative, you can use the Cloud SQL Auth proxy  to connect through the public IP address without a need for Authorized networks or for configuring SSL .

[1] https://cloud.google.com/sql/docs/postgres/connect-kubernetes-engine#private-ip
[2] https://cloud.google.com/kubernetes-engine/docs/how-to/alias-ips