How to read a variable from a file attached as Config map to a pod?

11/2/2018

Using Configmaps , I am attaching a text file containing environment variables to a Pod . When I log in to the POD and then run "env" command , I am able to see like below

env.txt=var1=123
var2=30000

I am trying to read var1 or var2 . I am unable to do it .

Appreciate your help

-- Balakumar Ezhilmaran
configmap
environment-variables
kubernetes

1 Answer

11/2/2018

As @RyanDawson answered in comments, you can proceed in two ways:

  1. Put variables directly to a ConfigMap. After that you can mount them to Pods. Here are some examples: link-1 and link-2

  2. Put variables into a file, and put the file into a ConfigMap. Mount the ConfigMap to a Pod, and after that use some script to parse it and add variables. Examples: link-3 and link-4

-- Artem Golenyaev
Source: StackOverflow