Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variables to args field in a yaml file, kubernetes

Tags:

kubernetes

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?

like image 739
Magic Avatar asked Jun 29 '17 18:06

Magic


People also ask

How do you pass arguments in Kubernetes?

To define arguments for the command, include the args field in the configuration file. The command and arguments that you define cannot be changed after the Pod is created. The command and arguments that you define in the configuration file override the default command and arguments provided by the container image.

How do you pass environment variables in pod?

When you create a Pod, you can set dependent environment variables for the containers that run in the Pod. To set dependent environment variables, you can use $(VAR_NAME) in the value of env in the configuration file.


1 Answers

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!

like image 98
samhain1138 Avatar answered Sep 20 '22 13:09

samhain1138