Is there an easy way to use container image name or tag as a ENV variable so that I can use it to provide the image name and tag in a pod (for version information). I am new user. This idea is to work-around my lack of knowledge in how kustomization.yaml can source "variables" from a config-map.yaml
Currently I set up an environment variable which I envsubt into kustomization.yaml, and from there I use that value twice: once for the image name change, and once to make a config map.
The actual objective is to enter this one piece of information only once, and have it be used in those two ways. If the image name was available to the container via the environment, that is one way since I would not need to inject the string into a config map to fill the container env; I could deduce it from the image metadata and therefore enter the value only once in kustomize, in the image name replacement. This would meet my objective, although it is not a general solution, it is a workaround specifically related to assuming image name metadata is available for free in the container. But this is not possible.
So another way is to template kustomization.yaml, which is what I have done: this is my current workaround. The philosophy of kustomize is no templating. However, avoiding duplicate entry of key literals is a higher priority for me.
In each "site" folder, I have something like this:
file: kustomization_pre_subst.yaml
resources:
- site-namespace.yaml
- site-config-map.yaml
- site-secret.yaml
- site-ingress.yaml
- ../base
namespace: test
images:
- name: django_api_sync-image
newName: "...dkr.ecr.aws.com/django_api_sync:image_prefix-${version}"
configMapGenerator:
- name: version-configmap
literals:
- django_api_sync_version="${version}"
So I have a configmap just with the version string.
In the base file this is used as part of the environment.
... fragment from a container spec:
envFrom:
- configMapRef:
name: site-configmap
- configMapRef:
name: common-configmap
- configMapRef:
name: version-configmap
- secretRef:
name: common-secret
- secretRef:
name: site-secret
This so far is the easiest solution that I can understand which lets me define the version string once, and have it select the image I want, and be passed to the container in env.
What I was hoping for is that I could instead define it literally in the site-configmap and then used this to provide the correct image name, that is, use the site-configmap as a source for kustomization.yaml rather than having to inject it like this.
pseudo code fragment of kustomization.yaml showing how it can source from a config-map (instead of injecting into a config map), like:
images:
- name: django_api_sync-image
newName: "...dkr.ecr.aws.com/django_api_sync:image_prefix-${version}"
env:
source-from: site-configmap
name: version
key: version
The point of the being that the version needs to defined only once.
However, even then it won't be as nice as doing envsubst.
I am surely missing something.