vesii
vesii

Reputation: 3128

How to handle lot of commands in Kubernetes config.yaml?

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.

Upvotes: 1

Views: 93

Answers (1)

Josh Beauregard
Josh Beauregard

Reputation: 2749

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

Upvotes: 1

Related Questions