I am trying to export environment to an Openshift pod via command. Currently I am able to leverage the command argument to run shell scripts (echo hi as example):
containers:
command:
['sh', '-c', 'echo hi && /opt/app-root/src/communities/entry.sh; node /opt/app-root/src/communities/main.js; echo $?']
This works well to start up my pod with the logs:
hi
Starting application on 0.0.0.0:8080
However, when I go to export environment variables they do not persist, in this example I'm trying to export MYVAR for use in the pod:
containers:
command:
['sh', '-c', 'export MYVAR=THIS && /opt/app-root/src/communities/entry.sh; node /opt/app-root/src/communities/main.js; echo $?']
This starts up the pod but MYVAR is not defined!
My end goal is to be able to run a script from Vault at pod start up:
containers:
command:
['sh', '-c', 'source /vault/secrets/EXSECRET && /opt/app-root/src/communities/entry.sh; node /opt/app-root/src/communities/main.js; echo $?']
Is there a way to set environment variables using a shell command after pod start up?
I've been stuck on this for quite some time and appreciate the help.
EDIT: My config
# THIS PART MOUNTS TO /vault/secrets/test ^
annotations:
vault.hashicorp.com/agent-inject: 'true'
vault.hashicorp.com/agent-inject-secret-test: namespace-nonprod/test
vault.hashicorp.com/agent-inject-template-test: |
{{`{{- with secret "namespace-nonprod/test" -}}
export dev_database_host="{{ .Data.data.test1 }}"
export dev_database_name="{{ .Data.data.test2 }}"
{{- end }}`}}
containers:
- resources: {}
command:
['sh', '-c']
args:
['source /vault/secrets/test && /opt/app-root/src/communities/entry.sh; node /opt/app-root/src/communities/main.js'] # not working ^
I can see the file is correctly mounted:
sh-4.4$ cat /vault/secrets/test
export dev_database_host="asdf1"
export dev_database_name="asdf2"
yet they are not available to env.
Thank you