<p>My container runs fine using docker-compose. But once I apply my deployment on Kubernetes it fails every time on the same error. No matter what I try. I'm stuck and would love some input/help.</p>
<p>I don't know how to debug this. A bit new at Kubernetes. So If someone can guide me, I can try to debug it.</p>
<p><strong>Error stack trace is the following</strong>:</p>
<pre class="lang-none prettyprint-override"><code>Running migration with alembic
INFO  [src.core.config] value for BACKEND_CORS_ORIGINS= ['http://localhost:3000', 'http://localhost:8001']
Traceback (most recent call last):
  File &quot;pydantic/env_settings.py&quot;, line 197, in pydantic.env_settings.EnvSettingsSource.__call__
  File &quot;pydantic/env_settings.py&quot;, line 131, in pydantic.env_settings.Config.parse_env_var
  File &quot;/usr/local/lib/python3.9/json/__init__.py&quot;, line 346, in loads
    return _default_decoder.decode(s)
  File &quot;/usr/local/lib/python3.9/json/decoder.py&quot;, line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())   
  File &quot;/usr/local/lib/python3.9/json/decoder.py&quot;, line 355, in raw_decode
    raise JSONDecodeError(&quot;Expecting value&quot;, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):   
  File &quot;/usr/local/bin/alembic&quot;, line 8, in &lt;module&gt;
    sys.exit(main())   
  File &quot;/usr/local/lib/python3.9/site-packages/alembic/config.py&quot;, line 590, in main
    CommandLine(prog=prog).main(argv=argv)
  File &quot;/usr/local/lib/python3.9/site-packages/alembic/config.py&quot;, line 584, in main
    self.run_cmd(cfg, options)
  File &quot;/usr/local/lib/python3.9/site-packages/alembic/config.py&quot;, line 561, in run_cmd
    fn(
  File &quot;/usr/local/lib/python3.9/site-packages/alembic/command.py&quot;, line 322, in upgrade
    script.run_env()
  File &quot;/usr/local/lib/python3.9/site-packages/alembic/script/base.py&quot;, line 569, in run_env
    util.load_python_file(self.dir, &quot;env.py&quot;)
  File &quot;/usr/local/lib/python3.9/site-packages/alembic/util/pyfiles.py&quot;, line 94, in load_python_file
    module = load_module_py(module_id, path)
  File &quot;/usr/local/lib/python3.9/site-packages/alembic/util/pyfiles.py&quot;, line 110, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
  File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 850, in exec_module
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 228, in _call_with_frames_removed
  File &quot;alembic/env.py&quot;, line 22, in &lt;module&gt;
    from src.core.config import settings
  File &quot;/app/src/core/config.py&quot;, line 72, in &lt;module&gt;
    settings = Settings()
  File &quot;pydantic/env_settings.py&quot;, line 40, in pydantic.env_settings.BaseSettings.__init__
  File &quot;pydantic/env_settings.py&quot;, line 75, in pydantic.env_settings.BaseSettings._build_values
  File &quot;pydantic/env_settings.py&quot;, line 200, in pydantic.env_settings.EnvSettingsSource.__call__
pydantic.env_settings.SettingsError: error parsing env var &quot;BACKEND_CORS_ORIGINS&quot;
Alembic migration done
[2022-11-15 21:25:36 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2022-11-15 21:25:36 +0000] [1] [INFO] Listening at: http://0.0.0.0:8001 (1)
[2022-11-15 21:25:36 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2022-11-15 21:25:36 +0000] [23] [INFO] Booting worker with pid: 23
[2022-11-15 21:25:37 +0000] [24] [INFO] Booting worker with pid: 24
[2022-11-15 21:25:37 +0000] [25] [INFO] Booting worker with pid: 25
[2022-11-15 21:25:40 +0000] [23] [ERROR] Exception in worker process
</code></pre>
<p>Now how it is set up.</p>
<p>My docker-compose file builds using a Dockerfile. The <strong>end of the Dockerfile</strong> is as follow. There is an ENTRYPOINT before the CMD instruction</p>
<pre class="lang-sh prettyprint-override"><code>ENTRYPOINT [&quot;./docker-entrypoint.sh&quot;]
CMD [&quot;./run.sh&quot;]
</code></pre>
<p><strong>docker-entrypoint.sh</strong></p>
<pre class="lang-sh prettyprint-override"><code>if [ -n &quot;$DB_SERVER&quot; ]; then
  ./wait-for-it.sh &quot;$DB_SERVER:${DB_PORT:-3306}&quot;
fi

# Run the main container command.
exec &quot;$@&quot;
</code></pre>
<p>This works because I can see the logs from the 'wait-for-it' script</p>
<p><strong>run.sh</strong> (where the error comes from)</p>
<pre class="lang-sh prettyprint-override"><code>export APP_MODULE=${APP_MODULE-src.main:app}
export HOST=${HOST:-0.0.0.0}
export PORT=${PORT:-8001}
export BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS:-'http://localhost:8001'}

echo &quot;Running migration with alembic&quot;
# Run migrations
alembic upgrade head
echo &quot;Alembic migration done&quot;

exec gunicorn -b $HOST:$PORT &quot;$APP_MODULE&quot; --reload --workers=3 --timeout 0 -k uvicorn.workers.UvicornWorker
</code></pre>
<p>I've set a default value to BACKEND_CORS_ORIGINS just in case.</p>
<p>In the stack trace above, at the 2nd line you can see a log. This is inside the pydantic validator for BACKEND_CORS_ORIGINS.
Here is part of my <strong>config.py</strong> file:</p>
<pre class="lang-python prettyprint-override"><code>class Settings(BaseSettings):
  BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = [&quot;http://localhost:3000&quot;, &quot;http://localhost:8001&quot;]

  @validator(&quot;BACKEND_CORS_ORIGINS&quot;, pre=True, allow_reuse=True)
      def assemble_cors_origins(cls, value: Union[str, List[str]]) -&gt; Union[List[str], str]:
          logger.info(f&quot;value for BACKEND_CORS_ORIGINS= {value}, type of BACKEND_CORS_ORIGINS= {type(value)}&quot;)
          backend_cors_origins = None
          if isinstance(value, str) and not value.startswith(&quot;[&quot;):
              backend_cors_origins = [i.strip() for i in value.split(&quot;,&quot;)]
          elif isinstance(value, (list, str)):
              backend_cors_origins = value
          logger.info(f&quot;value for BACKEND_CORS_ORIGINS= {backend_cors_origins}, type of BACKEND_CORS_ORIGINS= {type(backend_cors_origins)}&quot;)
          if backend_cors_origins:
              return backend_cors_origins
          raise ValueError(value)
</code></pre>
<p>For some reasons, I am not seeing the last part of the log where I want to see the type.</p>
<p>And to finish, here is my <strong>Deployment.yml</strong> file for Kubernetes</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: dev
  name: api-name
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api-name
  template:
    metadata:
      labels:
        app: api-name
    spec:
      imagePullSecrets:
        - name: secret_name
      containers:
      - name: api-name
        image: [private_registry]/api
        env:
        - name: MARIADB_USER
          value: 'db_user'
        - name: MARIADB_PASSWORD
          value: 'password'
        - name: MARIADB_SERVER
          value: 'IP_DB_SERVER'
        - name: MARIADB_DATABASE
          value: 'db_name'
        - name: MARIADB_PORT
          value: '1234'
        - name: BACKEND_CORS_ORIGINS
          value: 'http://localhost:8001'
        resources:
          limits:
            memory: &quot;512Mi&quot;
            cpu: &quot;500m&quot;
        ports:
        - containerPort: 8001
---
apiVersion: v1
kind: Service
metadata:
  namespace: dev
  name: svc-api
spec:
  type: NodePort
  selector:
    app: api-name
  ports:
  - port: 8001
    targetPort: 8001
</code></pre>
<p>Can someone help or point my in the right direction? Been trying everything I know to resolve this without any luck.</p>
<p>Maybe I need more config files for Kubernetes?</p>
<p>If I remove the alembic command in the <strong>run.sh</strong> script, I'm still getting the same error, but without the log inside the @validator</p>

kanadianDri3
<p>The issue seems to come from this line of export</p>
<pre><code>BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS:-'http://localhost:8001'} 
</code></pre>
<p>It seems to expect a list of URLs so maybe you can change the code</p>
<pre><code> - name: BACKEND_CORS_ORIGINS 
   value: 
     - 'localhost:8001' 
</code></pre>
<p>in Deployment.yml</p>
