How to refer Environment variables mentioned in openshift deployment, inside python code running in the pod of same deployment

8/27/2019

I am new to Openshift container platform. I am trying to deploy my ML model written in python, which serves the Json request based on authentication of name/password already mentioned in the py code.

    @app.before_request
def validate_request():
    try :
        if(request.authorization.username != auth_user or request.authorization.password != auth_password):
            return "Authentication failed: invalid or missing user/password."
    except:
        return "Authentication failed: invalid or missing user/password"

Now what I am doing is, I am creating a secrert dm in Openshift name-space and adding it in the deployment as below enter image description here

How can I use the username and password mentioned in this secret in my python code, I have tried with the openshift docbut it doesnt complete my requirement of using the value in the code.

-- Anurodh
containers
image
kubernetes-secrets
openshift
python

1 Answer

8/28/2019
auth_user = os.environ.get('principle')
auth_password = os.environ.get('credential')
-- Anurodh
Source: StackOverflow