无法连接到 Kubernetes 上的 PyMongo DB
Can't connect to PyMongo DB on Kubernetes
当我 运行 在 Docker 上时一切正常,但在我将它迁移到 Kubernetes 后它停止连接到数据库。它说:
pymongo.errors.ServerSelectionTimeoutError
pymongo.errors.ServerSelectionTimeoutError: connection closed
每当我尝试访问使用数据库的页面时。
我是这样连接的:
app.config['MONGO_DBNAME'] = 'pymongo_db'
app.config['MONGO_URI'] = 'mongodb://fakeuser:FakePassword@ds1336984.mlab.com:63984/pymongo_db'
有什么方法可以连接吗?
编辑:
我认为它与 Istio sidecars 有更多关系,因为当部署在 Kubernetes 减去 Istio 上时,它运行正常。该问题仅在 运行 Istio.
时出现
很可能 Istio(Envoy sidecar)正在控制出口流量。您可以检查您的集群中是否有任何 ServiceEntry
和 VirtuaService
用于您的特定应用程序:
$ kubectl -n <your-namespace> get serviceentry
$ kubectl -n <your-namespace> get virtualservice
如果它们存在,请检查它们是否允许流量到达 ds1336984.mlab.com
。如果它们不存在,您将不得不 create 它们。
当我 运行 在 Docker 上时一切正常,但在我将它迁移到 Kubernetes 后它停止连接到数据库。它说:
pymongo.errors.ServerSelectionTimeoutError
pymongo.errors.ServerSelectionTimeoutError: connection closed
每当我尝试访问使用数据库的页面时。
我是这样连接的:
app.config['MONGO_DBNAME'] = 'pymongo_db'
app.config['MONGO_URI'] = 'mongodb://fakeuser:FakePassword@ds1336984.mlab.com:63984/pymongo_db'
有什么方法可以连接吗?
编辑:
我认为它与 Istio sidecars 有更多关系,因为当部署在 Kubernetes 减去 Istio 上时,它运行正常。该问题仅在 运行 Istio.
时出现很可能 Istio(Envoy sidecar)正在控制出口流量。您可以检查您的集群中是否有任何 ServiceEntry
和 VirtuaService
用于您的特定应用程序:
$ kubectl -n <your-namespace> get serviceentry
$ kubectl -n <your-namespace> get virtualservice
如果它们存在,请检查它们是否允许流量到达 ds1336984.mlab.com
。如果它们不存在,您将不得不 create 它们。