I am trying to pass an environment variable in my deployment that should define a prefix based on a version number:
env:
- name: INDEX_PREFIX
value: myapp-$(VERSION)
$(VERSION)
is not defined in my deployment but is set in the docker image used by the pod.
I tried to use both $()
and ${}
but VERSION
is not interpolated in the environment of my pod. In my pod shell doing export TEST=myapp-${VERSION}
does work though.
Is there any way to achieve what I am looking for? ie setting an environment variable in my deployment that reference an environment variable set in the docker image?
VERSION
is an environment variable of the docker image. So you can assign it a value either inside the container or by passing
env:
- name : VERSION
value : YOUR-VALUE
In your case, VERSION
is either set by a script inside the docker container or in the Dockerfile.
You can do :
ENV INDEX_PREFIX myapp-${VERSION}
export INDEX_PREFIX=myapp-${VERSION}
In case you can't modify Dockerfile, you can try to :
docker inspect IMAGE
. command:
- '/bin/sh'
args:
- '-c'
- |
set -e
set -x
export INDEX_PREFIX=myapp-${VERSION}
IMAGE-entrypoint.sh IMAGE-ARGS
k8s documentation : https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/ Hope it could help you.