Created
October 15, 2018 12:48
-
-
Save kkc/a82e4fdd5197ad9cf29f98bc649ccc94 to your computer and use it in GitHub Desktop.
Using environment variables in Kubernetes deployment spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://serverfault.com/questions/791715/using-environment-variables-in-kubernetes-deployment-spec | |
A much easier/cleaner solution: envsubst | |
In deploy.yml: | |
LoadbalancerIP: $LBIP | |
Then just create your env var and run kubectl like this: | |
export LBIP="1.2.3.4" | |
envsubst < deploy.yml | kubectl apply -f - | |
You just put regular Bash variables into whatever file you want to use, in this case the YAML manifest, and have ensubst read that file. It will output the file with the env vars replaced by their values. You can also use it to create new files like this: | |
envsubst < input.yml > output.yml | |
envsubst is available in e.g. Ubuntu/Debian gettext package. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment