<p>I'm deploying a nodejs application into a kubernetes cluster. This application needs access to an external database which is public available under <code>db.external-service.com</code>. For this purpose a service of the type <code>ExternalName</code> is created.</p>
<pre><code>kind: Service
apiVersion: v1
metadata:
  name: postgres
spec:
  type: ExternalName
  externalName: db.external-service.com
</code></pre>
<p>In the deployment an environment variable which provides the database hostname for the application is set to the name of this service.</p>
<pre><code>env:
  - name: DB_HOST
    value: postgres
</code></pre>
<p>The problem is that when the nodejs application try to connect to the database ends up with this error message.</p>
<pre><code>Error: getaddrinfo ENOTFOUND postgres
</code></pre>
<p>Already tried to use the full hostname <code>postgres.&lt;my-namespace&gt;.svc.cluster.local</code> without success.</p>
<p>What cloud be wrong with this setup?</p>
<p><strong>EDIT:</strong></p>
<ul>
<li>It works if I use directly the plain ip address behind <code>db.external-service.com</code> in my pod configuration</li>
<li>It dose not work if I use the hostname directly in my pod configuration</li>
<li>I can ping the hostname with one of my pods: <code>kubectl exec my-pod-xxx -- ping db.external-service.com</code> has the right ip address</li>
</ul>

Markus
<p>It turns out that the Kubernetes worker nodes are not on the allow list from the database. So the connection timed out.</p>
