Using environment variables in Kubernetes deployment spec
A much easier/cleaner solution:
Then just create your env var and run kubectl like this:
export LBIP="220.127.116.11" 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
There was another pleasantly simple solution: I have a Google Compute Address
my-address defined, and I can apparently use it in the service spec like so:
With this as "external" source for IP addresses and secrets for passwords there is no more need for a provisioning tool (or templates) for my simple use case (within a GKE environment).
OBSOLETE NOW: I have decided on using a provisioning tool of sorts, namely "built-in"
sed, after all.
Deployment.yaml now contains a "template variable" e.g. in
and I deploy the service with, say, 18.104.22.168 as external IP address with
cat Deployment.yaml | sed s/\$\$EXTERNAL_IP/22.214.171.124/ | kubectl create -f -