Using multiple commands in a kubernetes yaml file

0 votes

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

http://kubernetes.io/v1.1/docs/user-guide/configuring-containers.html

apiVersion: v1
kind: Pod
metadata:
  name: hello-world
spec:  # specification of the pod’s contents
  restartPolicy: Never
  containers:
  - name: hello
    image: "ubuntu:14.04"
    env:
    - 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,450 points
49,936 views

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 further details, refer to the Kubernetes Course.

answered Aug 27, 2018 by DareDev
• 6,890 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:

containers:
  - name: mysqldump
    image: mysql
    command: ["/bin/sh", "-c"]
    args:
      - echo starting;
        ls -la /backups;
        mysqldump --host=... -r /backups/file.sql db_name;
        ls -la /backups;
        echo done;
    volumeMounts:
      ---
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
17,778 views
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, 2020 in Kubernetes by MD
• 95,460 points
4,779 views
0 votes
1 answer

How to create secrets from a text file in Kubernetes?

Hi@akhtar, Secrets can contain user credentials required by ...READ MORE

answered Jul 16, 2020 in Kubernetes by MD
• 95,460 points
2,690 views
+2 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
3,995 views
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,890 points
3,544 views
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,890 points
1,103 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP