kubernetes envFrom: how to load variables located into pod filesystem file

6/22/2018

I need to populate an env file located into pod filesystem filled by an init container previously.

I look up envFrom documentation but I've not been able to figure out how to use it and I've been able to find some relevant examples in internet.

Guess an init container creates a file on /etc/secrets/secrets.env, so the pod container spec has to look up on /etc/secrets/secrets.env in order to populate env variables.

-- Jordi
kubernetes

1 Answer

6/23/2018

You will not be able to reference any filesystem component to populate an environment variable using the PodSpec, because it creates a chicken-and-egg problem: kubernetes cannot create the filesystem without a complete PodSpec, but it cannot resolve variables in the PodSpec without access to the Pod's filesystem

If /etc/secrets is a volume that the initContainer and the normal container share, then you can supersede the command: of your container to source that into its environment before running the actual command, but that is as close as you're going to get:

containers:
- name: my-app
  command:
  - bash
  - -ec
  - |
    . /etc/secrets/secrets.env
    ./bin/run-your-server-command-here
-- mdaniel
Source: StackOverflow