Can't connect to PyMongo DB on Kubernetes

1/23/2019

Everything worked fine when I ran it on Docker, but after I migrated it to Kubernetes it stopped connecting to the DB. It says:

pymongo.errors.ServerSelectionTimeoutError
pymongo.errors.ServerSelectionTimeoutError: connection closed

whenever I try to access a page that uses the DB.

I connect like this:

app.config['MONGO_DBNAME'] = 'pymongo_db'
app.config['MONGO_URI'] = 'mongodb://fakeuser:FakePassword@ds1336984.mlab.com:63984/pymongo_db'

Any way to get it to connect?

Edit:

I think it has more so to do with the Istio sidecars as when deployed on Kubernetes minus Istio, it runs normally. The issue only appears when running Istio.

-- Annihil8
istio
kubernetes
pymongo
python

1 Answer

1/23/2019

Most likely Istio (the Envoy sidecar) is controlling egress traffic. You can check if you have any ServiceEntry and VirtuaService in your cluster for your specific application:

$ kubectl -n <your-namespace> get serviceentry
$ kubectl -n <your-namespace> get virtualservice

If they exist, check if they are allowing traffic to ds1336984.mlab.com. If they don't exist you will have to create them.

-- Rico
Source: StackOverflow