0

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

Bala
  • 1,077
  • 5
  • 15
  • 35
  • 1
    Could you put the env vars directly in a configmap rather than in a text file? Then you could do https://gist.github.com/troyharvey/4506472732157221e04c6b15e3b3f094 Or you could inject directly into Pods https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/ Or is it important to read from the text file? – Ryan Dawson Nov 02 '18 at 07:51
  • Yes , we can directly put it in the configmap . But the requirement was to make use of the existing text file. Checking if there is any way to do it – Bala Nov 02 '18 at 08:36
  • As Louis Bauman suggests, you can use a shell script to look for a file and then read environment variables from a file (https://stackoverflow.com/a/45971167/9705485). For this you'd want to mount the configmap as a file in the Pod using a Volume. You could then invoke the shell script to read this from your docker-entrypoint (https://success.docker.com/article/use-a-script-to-initialize-stateful-container-data) – Ryan Dawson Nov 02 '18 at 09:34

1 Answers1

0

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
  • 2,568
  • 12
  • 20