By arvtiwar
Hi Folks,
We have nodeJS application, which we are trying to deploy on DO K8S. we use mongodb atlas and mongoose, it works perfectly on DO on docker-compose. I am getting below error when deploying on K8S. Appreciate any help; I have already explored a lot but no help
https://stackoverflow.com/questions/56402472/kubernetes-node-js-container-cannot-connect-to-mongodb-atlas https://stackoverflow.com/questions/54213912/unable-to-connect-to-mongodb-atlas-cluster-from-a-kubernetes-cluster
Thanks, Arvind
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there!
It looks like you may have resolved this issue in your stack overflow:
I figured out the issue, my pod DNS was not configured to allow external connections, so I set dnsPolicy: Default in my YML
Let me know if you have any additional questions.
Regards,
John Kwiatkoski Senior Developer Support Engineer
Hi community,
Setting dnsPolicy: Default allows us to connect perfectly to mongodb atlas.
But, is there any way to get access to the mongodb atlas cluster without setting dnsPolicy: Default from DO K8s?
I also need communication with other services within the cluster.
I am using Istio and I have defined a Service Entry like this:
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: mongo-service-entry
spec:
hosts:
- xxx.mongodb.net
addresses:
- 0.0.0.0/0
ports:
- number: 27017
name: mongo
protocol: MONGO
location: MESH_EXTERNAL
resolution: NONE
But I can only get access white listening the droplets ip’s, something that obviously is not a good idea. Because these ip’s can change for example with autoscaling.
Thanks, Dalpheau
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
