1

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
  • 147
  • 1
  • 3
  • 7

2 Answers2

3

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
  • 1,965
  • 4
  • 29
  • 52
  • printenv is working fine. but if i want to access from the pod it is not showing the env variables. it shows the env variables that are defined in circus. i want to access env variables used in deployment.yaml files – Nantha kumar Oct 16 '18 at 14:18
  • 1
    @Nanthakumar Not sure what you are trying to achieve. I believe your python script is inside of pod?? You can access all environmental(Including environmental variables that you defined in yaml) – Veerendra Oct 17 '18 at 07:41
0

Accessing environment variables is pretty easy with the os module.

import os
os.environ.get("ENV_VAR_NAME")
kungphu
  • 4,279
  • 3
  • 25
  • 36