flask application running on Kubernete Pods doesn't respect port in configuration

3/1/2017

I have deployed my kubernete container onto google cloud platform, everything works as expected. But one thing confused me is that I specifically set my flask application to run on port 9001 and did set conatinerPort to 9001 as well using --port 9001 with kubectl run command. But somehow, the flask app still runs on port 80 and I was basically force to expose port 80 to my loading balancer..

Is there something I'm doing wrong or it's a bug with Kubernete? I was using docker:python:3 image to build my pods.

container configuration log from flask app

-- Ian Zhao
containers
docker
flask
kubernetes

1 Answer

3/1/2017

the containerPort has nothing to do with the port the flask application runs on. It is only the port that is EXPOSED by the container.

You need to check your flask application settings, where you should be able to set the port to use to run the app.

something like:

if __name__ == '__main__':
      app.run(host='0.0.0.0', port=9001)
-- MrE
Source: StackOverflow