Using multiple commands in a kubernetes yaml file

0 votes

So I followed the kubernetes documentation to execute a command using a yaml file:

apiVersion: v1
kind: Pod
  name: hello-world
spec:  # specification of the pod’s contents
  restartPolicy: Never
  - name: hello
    image: "ubuntu:14.04"
    - name: MESSAGE
      value: "hello world"
    command: ["/bin/sh","-c"]
    args: ["/bin/echo \"${MESSAGE}\""]

But I want to run multiple commands. How should I do it?

Aug 27, 2018 in Kubernetes by DragonLord999
• 8,420 points

3 answers to this question.

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

The first part(command: ["/bin/sh","-c"]) just tells the machine to run a shell and then run the following commands. The portion in args is where the actual commands are passed to the shell. You use semicolon to separate the commands. OR an easier wary in my opinion is to build your own dockerfile. Use RUN to execute your commands. for more information checkout Dockerfile and RUN.

answered Aug 27, 2018 by DareDev
• 6,850 points
how to pass the Dockerfile to this ? will args: ["dockerfile"] work??
0 votes

This should help..

command: ["/bin/sh","-c"]
args: ["c1; c2 && c3"]
answered Apr 23, 2019 by Himanshu
0 votes

Try something like this:

  - name: mysqldump
    image: mysql
    command: ["/bin/sh", "-c"]
      - echo starting;
        ls -la /backups;
        mysqldump --host=... -r /backups/file.sql db_name;
        ls -la /backups;
        echo done;
answered Apr 23, 2019 by lyza

Related Questions In Kubernetes

0 votes
1 answer
+1 vote
4 answers

Execute shell script file using kubernetes as a cron job

use /bin/sh instead of /bin/bash This solved it ...READ MORE

answered May 7, 2019 in Kubernetes by Sid
0 votes
1 answer

How to copy file inside a Pod in Kubernetes?

Hi@akhtar, You need to use the kubectl cp command ...READ MORE

answered Jul 5 in Kubernetes by MD
• 34,760 points
0 votes
1 answer

How to use gravitational teleport in a container/kubernetes environment?

You can use teleport to augment kubernetes ...READ MORE

answered Jun 28, 2018 in Kubernetes by ajs3033
• 7,280 points
0 votes
1 answer
+5 votes
7 answers

Docker swarm vs kubernetes

Swarm is easy handling while kn8 is ...READ MORE

answered Aug 27, 2018 in Docker by Mahesh Ajmeria
0 votes
1 answer

Cannot connect unix:///var/run/docker.sock in kubernetes using GitLab CI runner

Do not use this: DOCKER_DRIVER: overlay because OVERLAY is ...READ MORE

answered Oct 16, 2018 in Kubernetes by DareDev
• 6,850 points
0 votes
1 answer

deleting pods using kubernetes replication controller

The pods which are managed by ReplicationController ...READ MORE

answered Jul 24, 2018 in Kubernetes by DareDev
• 6,850 points