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,380 points

3 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,710 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 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 by lyza

Related Questions In Kubernetes

0 votes
1 answer
+1 vote
4 answers
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,120 points
0 votes
1 answer
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,710 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,710 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.