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
  • 153
  • 1
  • 3
  • 8

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 K
  • 2,145
  • 7
  • 32
  • 61
  • 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 K 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,592
  • 3
  • 28
  • 37