python app in k8s with mongodb raise InvalidURI('Bad database name "%s"' % dbas

Viewed 344

I have python app deployed in K8s this python app will be connected to MongoDB the same python app and mongodb is working in docker compose as expected but when I deploy in k8s I am getting this error

In docker-compose all works as expected but in k8s I am unable to fix this especially it says raise InvalidURI('Bad database name "%s"' % dbase) I am not sure from where these values are coming from

mongodb-svc

Name:              mongo
Namespace:         default
Labels:            io.kompose.service=mongo
Annotations:       kompose.cmd: kompose convert
                   kompose.version: 1.21.0 (992df58d8)
Selector:          io.kompose.service=mongo
Type:              ClusterIP
IP:                10.0.192.239
Port:              27018  27018/TCP
TargetPort:        27017/TCP
Endpoints:         10.240.0.25:27017
Session Affinity:  None
Events:            <none>

python-app-deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: pythonapp
  name: pythonapp
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: pythonapp
  strategy: {}
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert
        kompose.version: 1.21.0 (992df58d8)
      creationTimestamp: null
      labels:
        io.kompose.service: pythonapp
    spec:
      containers:
      - env:
        - name: MONGO_AUTH_SOURCE
          value: "ma-db-dev"
        - name: MONGO_HOST
          value: "mongo"
        - name: RABBIT_MQ_VHOST
          value: "/vhost1"
        - name: SERVER_IP
          value: "rabbitmq"
        image: pythonapp:latest
        imagePullPolicy: ""
        name: pythonapp
        ports:
        - containerPort: 5005
        resources: {}
      restartPolicy: Always
      serviceAccountName: ""
      volumes: null
[2020-07-21 17:01:27 +0000] [7] [INFO] Starting gunicorn 20.0.4
[2020-07-21 17:01:27,918] {gunicorn.conf.py:21} werkzeug - DEBUG - Gunicorn:on_starting: <gunicorn.arbiter.Arbiter object at 0x7f267aaa7ed0>
[2020-07-21 17:01:27 +0000] [7] [DEBUG] Arbiter booted
[2020-07-21 17:01:27 +0000] [7] [INFO] Listening at: http://0.0.0.0:5005 (7)
[2020-07-21 17:01:27 +0000] [7] [INFO] Using worker: gevent
[2020-07-21 17:01:27,919] {gunicorn.conf.py:36} werkzeug - DEBUG - Gunicorn:when_ready: <gunicorn.arbiter.Arbiter object at 0x7f267aaa7ed0>
[2020-07-21 17:01:27 +0000] [10] [INFO] Booting worker with pid: 10
[2020-07-21 17:01:27 +0000] [11] [INFO] Booting worker with pid: 11
[2020-07-21 17:01:28 +0000] [7] [DEBUG] 2 workers
[2020-07-21 17:01:31 +0000] [11] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/ggevent.py", line 162, in init_process
    super().init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
    mod = importlib.import_module(module)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/mmm_server/production.py", line 5, in <module>
    flask_app = create_api_app()
  File "/mmm_server/app.py", line 19, in create_api_app
    mongo.init_app(app)
  File "/usr/local/lib/python3.7/site-packages/flask_pymongo/__init__.py", line 147, in init_app
    parsed_uri = uri_parser.parse_uri(uri)
  File "/usr/local/lib/python3.7/site-packages/pymongo/uri_parser.py", line 425, in parse_uri
    raise InvalidURI('Bad database name "%s"' % dbase)
pymongo.errors.InvalidURI: Bad database name "/10"
[2020-07-21 17:01:31 +0000] [11] [INFO] Worker exiting (pid: 11)
[2020-07-21 17:01:31,334] {gunicorn.conf.py:52} werkzeug - DEBUG - Gunicorn:worker_exit: server: <gunicorn.arbiter.Arbiter object at 0x7f267aaa7ed0> 
worker: <Worker 11>
[2020-07-21 17:01:31 +0000] [10] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/ggevent.py", line 162, in init_process
    super().init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
    mod = importlib.import_module(module)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/mmm_server/production.py", line 5, in <module>
    flask_app = create_api_app()
  File "/mmm_server/app.py", line 19, in create_api_app
    mongo.init_app(app)
  File "/usr/local/lib/python3.7/site-packages/flask_pymongo/__init__.py", line 147, in init_app
    parsed_uri = uri_parser.parse_uri(uri)
  File "/usr/local/lib/python3.7/site-packages/pymongo/uri_parser.py", line 425, in parse_uri
    raise InvalidURI('Bad database name "%s"' % dbase)
pymongo.errors.InvalidURI: Bad database name "/10"
[2020-07-21 17:01:31 +0000] [10] [INFO] Worker exiting (pid: 10)
[2020-07-21 17:01:31,344] {gunicorn.conf.py:52} werkzeug - DEBUG - Gunicorn:worker_exit: server: <gunicorn.arbiter.Arbiter object at 0x7f267aaa7ed0> 
worker: <Worker 10>
[2020-07-21 17:01:31,710] {gunicorn.conf.py:52} werkzeug - DEBUG - Gunicorn:worker_exit: server: <gunicorn.arbiter.Arbiter object at 0x7f267aaa7ed0> 
worker: <Worker 10>
[2020-07-21 17:01:31 +0000] [7] [INFO] Shutting down: Master
[2020-07-21 17:01:31 +0000] [7] [INFO] Reason: Worker failed to boot
0 Answers
Related