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

<pre><code>pymongo.errors.ServerSelectionTimeoutError
pymongo.errors.ServerSelectionTimeoutError: connection closed
</code></pre>

<p>whenever I try to access a page that uses the DB.</p>

<p>I connect like this:</p>

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

<p>Any way to get it to connect?</p>

<p>Edit:</p>

<p>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.</p>

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

<pre><code>$ kubectl -n &lt;your-namespace&gt; get serviceentry
$ kubectl -n &lt;your-namespace&gt; get virtualservice
</code></pre>

<p>If they exist, check if they are allowing traffic to <code>ds1336984.mlab.com</code>. If they don't exist you will have to <a href="https://istio.io/docs/tasks/traffic-management/egress/" rel="nofollow noreferrer">create</a> them.</p>
