Passing variables to args field in a yaml file, kubernetes

6/29/2017

I am writing a YAML file to use Kubernetes and I wondering how to pass variables to args field.

I need to do something like this :

args:  ['--arg1=http://12.12.12.12:8080','--arg2=11.11.11.11']

But I don't want to hard code those values for --arg1 and --arg2, instead it should be like,

args:  ['--arg1='$HOST1,'--arg2='$HOST2]

How should I do this?

-- Magic
kubernetes

1 Answer

9/25/2018

You have two options that are quite different and really depend on your use-case, but both are worth knowing:

1) Helm would allow you to create templates of Kubernetes definitions, that can use variables.
Variables are supplied when you install the Helm chart, and before the resulting manifests are deployed to Kubernetes.
You can change the variables later on, but what it does is regenerate the YAML and re-deploy "static" versions of the result (template+variables=YAML that's sent to Kubernetes)

2) ConfigMaps allow you to separate a configuration from the pod manifest, and share this configuration across several pods/deployments.
You can later reference the ConfigMap from your pod/deployment manifests.

Hope this helps!

-- samhain1138
Source: StackOverflow