Hi I’m trying to create a simple rest api service using flask in python. So basically what I did was create a flask app (basic hello world) and created a docker container to expose it using gunicorn like this
FROM python:3.7 RUN mkdir /app WORKDIR /app ADD . /app/ RUN pip install flask RUN pip install gunicorn CMD ["gunicorn", "-w", "1", "-b", ":8080", "-t", "360", "wsgi:app"]
I tested it using docker run like this
docker run -p 5001:8080 hello-python
and I can access the app using
After I wanted to create a deployment for this container in kubernetes (running on docker) so I have this manifest file
apiVersion: apps/v1 kind: Deployment metadata: name: hello-python spec: replicas: 2 selector: matchLabels: app: hello-python template: metadata: labels: app: hello-python spec: containers: - name: hello-python image: hello-python:latest imagePullPolicy: Never ports: - containerPort: ???
I think I understand everything in the file, except for containerPort. So My questions are as follows
1 - First of all when using flask, it says that not to use the bundled web server for production and to instead use something like gunicorn + nginx - does this still apply when running the app within a container? Do I still need to wire up gunicorn to expose the flask app?
2 - Assuming I keep my app as is with gunicorn - I set it to use the port 8080. When I ran the app in docker I had to direct the traffic from external port 5001 to internal port 8080. Is this what containerPort field is doing as well? or is it for something else? My confusion results from reading this article https://medium.com/faun/should-i-configure-the-ports-in-kubernetes-deployment-c6b3817e495 which indicates that the containerPort is purely informative and we don’t actually have to specify it.
The end goal is to expose the service to the network outside the cluster (i.e. just my local machine network for now)