Unable to connect to server ( postgres ) - GCP - Kubernetes

12/15/2019

)

I want to connect to my Postgres DB . I use deployment NodePort IP for the host field and also data from config file :

data:
  POSTGRES_DB: postgresdb
  POSTGRES_PASSWORD: my_password
  POSTGRES_USER: postgresadmin

enter image description here

But I get error . What do I do wrong ? If you need more info - let me know .

-- Andrey Radkevich
google-cloud-platform
kubernetes
postgresql

1 Answer

12/15/2019

Unless you are connected to your cluster through VPN (or direct connect), you can't access 10.121.8.109. It's a private IP address and only available for apps and services within you VPC.

You need to create public access for your node port service. Try kubectl get service to find out the External IP for your service. Then try to connect to your IP address from External IP.

Rather than using NodePort service, you are better off using Load Balancer type service which might give you better flexibility in managing this especially in a production env. But it will cost a little more Likelihood of an IP Address to change is high, but load balancer or ingress service would automatically manage this for you through a fixed DNS. So you need to weigh the pros and cons of using service type based on your workload.

-- Parth Mehta
Source: StackOverflow