zalando / spilo

Highly available elephant herd: HA PostgreSQL cluster using Docker
Apache License 2.0
1.51k stars 371 forks source link

Unable to connect to cluster from application but able to connect from within application container when tried manually #953

Open preetam-uptimeai opened 7 months ago

preetam-uptimeai commented 7 months ago

I have setup spilo cluster and I am able to connect to it from within the container hosting the cluster.

I have a deployment file which hosts a nodejs application and tries to connect to the psql cluster.

When i exec into the nodejs container and run psql -h postgresql-cluster.default.svc.cluster.local -U postgres and enter password, I am able to connect to db. (postgresql-cluster.default.svc.cluster.local is the name of the CLusterIP service which exposes the psql cluster)

But when I try to connect to db from nodejs application using 'pg' npm module with same host, user and password, I get the following error

error: pg_hba.conf rejects connection for host "10.244.4.39", user "postgres", database "uptime", no encryption

Below is the content fro pg_hba.config file

cat pg_hba.conf Do not edit this file manually! It will be overwritten by Patroni! local all all trust hostssl all +zalandos 127.0.0.1/32 pam host all all 127.0.0.1/32 md5 hostssl all +zalandos ::1/128 pam host all all ::1/128 md5 local replication standby trust hostssl replication standby all md5 hostnossl all all all reject hostssl all +zalandos all pam hostssl all all all md5

exit

Please guide me through