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