3

I have a bash script in a Docker image to which I can pass a command line argument through docker run (having specified the bash script in ENTRYPOINT and a default parameter in CMD like in this answer). So I would run something like

docker run my_docker_test argument_1 

Now I would like to deploy multiple (ca. 50) containers to OpenShift or Kubernetes, each with a different value of the argument. I understand that in Kubernetes I could specify the command and args in the object configuration yaml file. Is there a possibility to pass the argument directly from the command line like in docker run, e.g. passing to kubectl or oc, without the need to create a new yaml file each time I want to change the value of the argument?

1
  • In general in Kubernetes you should prefer deploying things via YAML files; a templating tool like Helm could help this specific use case. Commented Nov 28, 2019 at 17:47

3 Answers 3

7

The right answer is from @Jonas but you can also use environment variables in your yaml file as stated below:

As an alternative to providing strings directly, you can define arguments by using environment variables

env: - name: ARGUMENT value: {{ argument_1 }} args: ["$(ARGUMENT)"] 

Where {{ argument_1 }} is an environment variable.

Sign up to request clarification or add additional context in comments.

Comments

4

The following command should do it:

kubectl run my-app --image=my_docker_test -- argument_1 

2 Comments

What is this my-app?
you write the name that you want on app there
1

I think the best way is to define them in your manifest (yaml file) in the container level, although environmental variables also work.

If you spawn multiple containers in your pod (not usually recommended but sometimes useful) I think the environmental variables is messy as they are defined on a pod level.

Note: If you do define environmental variables they are parsed as strings so you need to put numeric values in quotes.

containers: - name: <foo> image: <bar>:latest args: ["<argumet_value>"] 

1 Comment

What could be the advantages of this approach? Seems interesting

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.