1

In my Kubernetes config.yaml I have:

command: ["sh", "-c", "command1; command2; command3;"]`

a lot of commands can complicate the config file and it will be hard to reat. What is the best approach here? Is it possible to create a script that will have those commands? I will be glad to see an example.

vesii
  • 2,760
  • 4
  • 25
  • 71
  • Can you treat this like any other substantial coding effort, build and test it outside containers, and then build an image around it? (A `FROM busybox` image plus a POSIX shell script would be pretty small.) – David Maze Apr 07 '21 at 00:41
  • please chech here a lot of options [How to set multiple commands in one yaml file with Kubernetes?](https://stackoverflow.com/questions/33887194/how-to-set-multiple-commands-in-one-yaml-file-with-kubernetes) – Vit Apr 07 '21 at 11:09

1 Answers1

1

Two ways:

The quick and dirty way .

The command object a an array object in yaml so you can reformat like.

command:
 - "sh"
 - "-c"
 - "command1; command2; command3;"
 - "ect"

A little more elegant way:

  • Create a config map object as a shell script with all your commands.
  • Attach that config map as a mounted volume to your deployment/statefulset, cron , ect. object
  • Call the shell script from your command

https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-configmaps-from-files

Josh Beauregard
  • 2,498
  • 2
  • 20
  • 37