Cannot connect to postgres pod in kubernetes

10/4/2021

I used helm chart to install Postgresql in Kubernetes.

I cannot connect to my Postgres inside my app server. When I tried to connect to db. Server throw to me a error about HostNotFoundError.

Anyone have any experience about install the database on the Kubernetes. Please help me.

Thanks!

kubectl get pod

NAME                                                      READY   STATUS    RESTARTS   AGE
apollo-b47f886f-g9c8f                                     1/1     Running   0          2d19h
jupiter-7799cf84db-zfm9q                                  1/1     Running   0          5m23s
jupiter-migration-kkmqz                                   0/1     Error     0          3h22m
nginx-ingress-ingress-nginx-controller-55d6b7dc57-nn8q6   1/1     Running   0          20d
postgres-postgresql-0                                     1/1     Running   0          18h
kubectl get services

NAME                                               TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)                      AGE
apollo                                             ClusterIP      10.92.8.51     <none>          80/TCP                       20d
jupiter                                            ClusterIP      10.92.7.8      <none>          80/TCP                       2d14h
kubernetes                                         ClusterIP      10.92.0.1      <none>          443/TCP                      20d
nginx-ingress-ingress-nginx-controller             LoadBalancer   10.92.11.40    External IP   80:31096/TCP,443:31324/TCP   20d
nginx-ingress-ingress-nginx-controller-admission   ClusterIP      10.92.14.117   <none>          443/TCP                      20d
postgres-postgresql                                ClusterIP      10.92.3.97     <none>          5432/TCP                     18h
postgres-postgresql-headless                       ClusterIP      None           <none>          5432/TCP
sequelize config

module.exports = {
  production: {
    username: postgres,
    password: mypassword,
    database: jupiter,
    host: postgres-postgresql,
    dialect: 'postgres',
  },
};
Server logs

error HostNotFoundError [SequelizeHostNotFoundError]: getaddrinfo ENOTFOUND postgres-postgresql
    at Client._connectionCallback (/app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:175:24)
    at Client._handleErrorWhileConnecting (/app/node_modules/pg/lib/client.js:305:19)
    at Client._handleErrorEvent (/app/node_modules/pg/lib/client.js:315:19)
    at Connection.emit (node:events:394:28)
    at Socket.reportStreamError (/app/node_modules/pg/lib/connection.js:52:12)
    at Socket.emit (node:events:394:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  parent: Error: getaddrinfo ENOTFOUND postgres-postgresql
06:02:30 0|jupiter  |
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'postgres-postgresql\n'
  },
  original: Error: getaddrinfo ENOTFOUND postgres-postgresql
06:02:30 0|jupiter  |
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'postgres-postgresql\n'
  }
}
-- Hiep Nguyen
kubernetes
kubernetes-helm
postgresql
sequelize.js

1 Answer

10/4/2021

if in case what @AndD pointed out is cleared and still didn't work..

  1. I would check my coreDNS pod under kube-system if there is an issue.

  2. You could also try using the FQDN (fully qualified domain name) postgres-postgresql.YOURNAMESPACE.svc.cluster.local

  3. the postgres-postgresql service IP

  4. postgres-postgresql-0 incase there is a problem with your svc networking

-- letthefireflieslive
Source: StackOverflow