0
votes

I am new to Python and kubernetes. I am trying to deploy a docker container in k8s pod on GCP and after an hr or so it is killed. Below is the docker file and the script that I am trying to execute.

FROM python:3.7-slim AS build

WORKDIR /app

COPY . .

RUN pip3 install pymysql && pip3 install waitress

ENV DICT_FILE="/opt/srv/projects.dict" \
    MODEL_FILE="/opt/srv/projects.model.cpickle" \
    INDEX_FILE="/opt/srv/projects.index" \
    EXTERNAL_INDEX_FILE="/opt/srv/projects.mm.metadata.cpickle"

EXPOSE 5000
EXPOSE 3306

ENTRYPOINT ["/bin/sh", "serve.sh"]

serve.sh

#!/bin/sh

mkdir -p /opt/srv
python3 setup.py bdist_wheel
pip3 install dist/app_search*.whl && semanticsearch-preprocess

cp /app/dist/app_search*.whl /opt/srv/
cd /opt/srv

pip3 install app_search*.whl

waitress-serve --call app_search.app:main

The last log I see before the crash is

Successfully installed Flask-1.1.2 Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-0.16.1 aniso8601-8.0.0 attrs-20.2.0 certifi-2020.6.20 chardet-3.0.4 click-7.1.2 flask-restplus-0.12.1 gensim-3.6.0 idna-2.10 importlib-metadata-2.0.0 itsdangerous-1.1.0 jsonschema-3.2.0 numpy-1.19.2 pyrsistent-0.17.3 pytz-2020.1 requests-2.24.0 scipy-1.5.2 six-1.15.0 smart-open-3.0.0 app-search-0.0.9 urllib3-1.25.10 zipp-3.3.0

If I docker build and run on my local machine, the app works and is served on port 5000

1
You should be running those "install" commands in your Dockerfile (as your subsequent question does). Are there log messages saying what wasn't successfully installed?David Maze

1 Answers

1
votes

When you run your container on Kubernetes, the used os is COS (Container Optimized OS). The container that on it are secure and prevent any update at runtime. Here, you try to add dependencies and to copy file at runtime, it can't work!

Install all the stuff that you need when you build your container, and only execute your container at runtime.

Of course, if you attach volume to your container, you can read and write on this mounted volume

On your local environment, you don't have this same constrain and Docker run is more fair with you!