1

I am trying to run a python flask app in https mode in openshift 4.7. I have my python flask app listening at port 8080 and this port is exposed through dockerFile configuration as shown below. I have redirected the https requests through the configuration in Openshift console by doing Service Port Mapping for https port 443 to pod port 8080. You can configure this by going to Openshift Console > Project > Services > Service Details and select your app. But still I can't access the service in https mode. When I try to access in https mode I get the error The application is currently not serving requests at this endpoint. It may not have been started or is still starting.

When I do normal deployment through oc cli and do not do any ssl configuration through openshift console, the app works fine in http mode. Please advise on how to run this in https mode

my app.py code is below

from flask import Flask, jsonify, request, redirect

app = Flask(__name__)

@app.route('/<string:name>/')
def helloName(name):
    print(request)
    return "Hello " + name

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8080, debug = True)

my Dockerfile content is as below and I am exposing port 8080 from it

# set base image 
FROM registry.redhat.io/rhel8/python-38

# copy the dependencies file to the working directory
COPY requirements.txt .

# Configure PIP with local Nexus
ENV PIP_TRUSTED-HOST=nexus.company.com:8443
ENV PIP_INDEX=https://nexus.company.com:8443/repository/pypi-group/pypi
ENV PIP_INDEX-URL=https://nexus.company.com:8443/repository/pypi-group/simple
ENV PIP_NO-CACHE-DIR=false
ENV PIP_TIMEOUT=600

RUN touch ~/.netrc && \
    echo "machine nexus.company.com" >> ~/.netrc && \
    echo "login ${NEXUS_USER}" >> ~/.netrc && \
    echo "password ${NEXUS_TOKEN}" >> ~/.netrc 

# install dependencies
RUN pip install -U pip \ 
pip install -r requirements.txt

# copy the content of the local src directory to the working directory
COPY src/ .

EXPOSE 8080
# command to run on container start
CMD [ "python3", "./app.py" ]

Requirements.txt has only Flask

akarahman
  • 235
  • 2
  • 15

1 Answers1

0

Two things here:

  1. With host="0.0.0.0" Flask listens to the IP of the machine it is running on. I think changing this to 127.0.0.1 should be good.

    app.run(host='127.0.0.1', port=8080, debug = True)

  2. Probably even more important, the .run() method from Flask is only for development, for production you should use something like gunicorn or something.

link: https://gunicorn.org/

Cheers, T

Thomas
  • 26
  • 1
  • I tried your first response, still the issue is not resolved. Any specific tips on configuring this app in OpenShift – akarahman Oct 05 '21 at 04:53