Kubernetes - Passing multiple commands to the container

use this command

command: ["/bin/sh","-c"]
args: ["command one; command two && command three"]

Jordan's answer is correct.

But to improve readability I would prefer:

apiVersion: v1
kind: Pod
metadata:
  name: hello-world
spec:  # specification of the pod’s contents
  restartPolicy: Never
  containers:
  - name: hello
    image: "ubuntu:14.04"
    command: ["/bin/sh"]
    args:
      - -c
      - >-
          command1 arg1 arg2 &&
          command2 arg3 &&
          command3 arg4

Read this to understand YAML block scalar (The above >- format).


There can only be a single entrypoint in a container... if you want to run multiple commands like that, make bash be the entry point, and make all the other commands be an argument for bash to run:

command: ["/bin/bash","-c","touch /foo && echo 'here' && ls /"]

Tags:

Kubernetes