So I've been struggling with this all afternoon. I can't at all get my NodeJS application running on kubernetes to connect to my MongoDB Atlas database.
In my application I've tried running
mongoose.connect('mongodb+srv://admin:<password>@<project>.gcp.mongodb.net/project_prod?retryWrites=true&w=majority', { useNewUrlParser: true })
but I simply get the error
UnhandledPromiseRejectionWarning: Error: querySrv ETIMEOUT _mongodb._tcp.<project>.gcp.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:196:19)
(node:32) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 17)
I've tried setting up a ExternalName service too, but using either the URL or the ExternalName results in me not being able to connect to the database.
I've whitelisted my IP on MongoDB Atlas, so I know that isn't the issue.
It also seems to work on my local machine, but not in the kubernetes pod. What am I doing wrong?
I figured out the issue, my pod DNS was not configured to allow external connections, so I set dnsPolicy: Default
in my YML, because oddly enough Default
is not actually the default value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With