I'm trying to deploy my app in Google Cloud Kubernetes Engine; it consists of backend (in Node.JS) and a DB (MongoDB).
When I'm testing it on my local VM within Minikube it works as expected - I can connect from the API to the DB.
However, when deploy it on GCP my API can't connect, and after checking the API's pod logs, I see the MongoDB :: connection error: MongoTimeoutError: Server selection timed out after 30000 ms
error.
I don't know if it matters, but those two microservices are in the same node.
Is there any difference to be aware of between the local Minikube setup and the GCP setup?
Make sure the pods are running and there is no error in logs of the pod. You might have a network policy which blocks pod to pod communication.Check if the cluster network policy enforcement is enabled and try disabling cluster network policy enforcement using cloud cli
gcloud container clusters update [CLUSTER_NAME] --no-enable-network-policy
https://cloud.google.com/kubernetes-engine/docs/how-to/network-policy
After all this helped me: Google Cloud Platform - Can't connect to mongodb
First answer shows how to add firewall rule but second is even more important to change IP address inside the mongodb config. May it be done easier?