On , I learnt ...

About envsubst

Am learning Kubernetes and was looking for ways to dynamically create YAML resource files.

I stumbled upon the envsubst utility which will substitute in the value of environment variables to STDIN.


> export foo=bar
> echo '$foo'
> echo '$foo' | envsubst

So you could have a Kubernetes deployment.yml file where the image tag is set by a environment variable instead of being hard-coded:

> export DOCKER_IMAGE_TAG=...
> cat deployment.yml | envsubst | kubectl apply -f -

I’m sure there are better ways of setting up Kubernetes deployment pipelines but this is a neat trick to know.