<p>I used helm chart to install Postgresql in Kubernetes.</p>
<p>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.</p>
<p>Anyone have any experience about install the database on the Kubernetes. Please help me.</p>
<p>Thanks!</p>
<pre><code>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
</code></pre>
<pre><code>kubectl get services

NAME                                               TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)                      AGE
apollo                                             ClusterIP      10.92.8.51     &lt;none&gt;          80/TCP                       20d
jupiter                                            ClusterIP      10.92.7.8      &lt;none&gt;          80/TCP                       2d14h
kubernetes                                         ClusterIP      10.92.0.1      &lt;none&gt;          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   &lt;none&gt;          443/TCP                      20d
postgres-postgresql                                ClusterIP      10.92.3.97     &lt;none&gt;          5432/TCP                     18h
postgres-postgresql-headless                       ClusterIP      None           &lt;none&gt;          5432/TCP
</code></pre>
<pre><code>sequelize config

module.exports = {
  production: {
    username: postgres,
    password: mypassword,
    database: jupiter,
    host: postgres-postgresql,
    dialect: 'postgres',
  },
};
</code></pre>
<pre><code>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'
  }
}
</code></pre>

Hiep Nguyen
<p>if in case what @AndD pointed out is cleared and still didn't work..</p>
<ol>
<li><p>I would check my coreDNS pod under kube-system if there is an issue.</p>
</li>
<li><p>You could also try using the FQDN (fully qualified domain name) postgres-postgresql.[YOURNAMESPACE].svc.cluster.local</p>
</li>
<li><p>the postgres-postgresql service IP</p>
</li>
<li><p>postgres-postgresql-0 incase
there is a problem with your svc networking</p>
</li>
</ol>
