How to access environment variables inside container at runtime ?

10/15/2018

We aware of that we can define environment variables in pod/containers. i wanted to use the same environment variable inside the container at runtime.

ex: i am running a webapplication using python , inside that how to i get the values of environment values?

-- Nantha kumar
kubernetes
python

2 Answers

10/15/2018

Accessing environment variables is pretty easy with the os module.

import os
os.environ.get("ENV_VAR_NAME")
-- kungphu
Source: StackOverflow

10/15/2018

First go inside the pod or exec the bash(kubeclt exec -it <pod_name> bash) and run printenv to get some idea what are the environmental variables available.

From Python

import os
os.environ['MYCUSTOMVAR']
-- Veerendra Kakumanu
Source: StackOverflow