1

I am new to Kubernetes. I have an issue is if my args are so long and it needs to go to the second line, how to correct the format without messup the Kubernetes yaml file

For exapmle:

command: ["/bin/sh"]
args: ["-c", "while true; do echo hello; sleep 10;done, while true; do echo hello; sleep 10;done,while true; do echo hello; sleep 10;done,while true; do echo hello; sleep 10;done,while true; do echo hello; sleep 10;done,while true; do echo hello; sleep 10;done,"]

Thanks

Rico
  • 58,485
  • 12
  • 111
  • 141
qing zhang
  • 125
  • 1
  • 4
  • 13
  • Can you write a shell script, `COPY` it into your Docker image, and make that the image's default `CMD`? You wouldn't set `command:` or `args:` with that setup, just let Kubernetes run the container's default command. That would give you something that's easier to format and test. – David Maze Dec 17 '20 at 03:06

2 Answers2

5

K8s manifests are compliant with the YAML standard. So you can do multiline YAML. For example:

--- 
args: 
  - -c   array multiline notation
  - |
      while true; do echo hello; sleep 10;done,
      while true; do echo hello; sleep 10;done,
      while true; do echo hello; sleep 10;done,
      while true; do echo hello; sleep 10;done,
      while true; do echo hello; sleep 10;done,
      while true; do echo hello; sleep 10;done,
command: 
  - /bin/sh

✌️

Rico
  • 58,485
  • 12
  • 111
  • 141
3

Use a YAML multiline string:

command: ["/bin/sh"]
args: 
  - "-c"
  - |
    while true; do echo hello; sleep 10;done,
    while true; do echo hello; sleep 10;done,
    while true; do echo hello; sleep 10;done,
    while true; do echo hello; sleep 10;done
    etc...

More on the topic

Alex
  • 34,899
  • 5
  • 77
  • 90