Home > Mobile >  Running multiple python scripts from kubernetes
Running multiple python scripts from kubernetes

Time:10-28

I want to run multiple python scripts with passing arguments to the python script, how I can do that? Is it possible in Kubernetes?

Like I have multiple python scripts with different inputs: "./main.py", "1" , "./main2.py", "2", "./main3.py", "3" I can not put all of them in one file to run need to run them separately here, is there any way to do that?

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: [ "python" ]
        args: [ "./main.py", "1" ]

CodePudding user response:

can you try as shown below

kind: Pod
metadata:
  name: hello-world-1
spec:  # specification of the pod’s contents
  restartPolicy: Never
  containers:
  - name: hello
    image: "ubuntu:14.04"
    env:
    - name: MESSAGE
      value: "hello world"
        command: [ "python" ]
        args: [ "./main.py", "1" ]
---
kind: Pod
metadata:
  name: hello-world-2
spec:  # specification of the pod’s contents
  restartPolicy: Never
  containers:
  - name: hello
    image: "ubuntu:14.04"
    env:
    - name: MESSAGE
      value: "hello world"
        command: [ "python" ]
        args: [ "./main2.py", "2" ]
---
kind: Pod
metadata:
  name: hello-world-3
spec:  # specification of the pod’s contents
  restartPolicy: Never
  containers:
  - name: hello
    image: "ubuntu:14.04"
    env:
    - name: MESSAGE
      value: "hello world"
        command: [ "python" ]
        args: [ "./main3.py", "3" ]

CodePudding user response:

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","python ./main.py 1 && python ./main.py 2 && python ./main.py 3"]

or you can run multiple containers in one pod:

apiVersion: v1
kind: Pod
metadata:
  name: mc1
spec:
  volumes:
  - name: html
    emptyDir: {}
  containers:
  - name: hello-world-1
    image: "ubuntu:14.04"
    env:
    - name: MESSAGE
      value: "hello world"
        command: [ "python" ]
        args: [ "./main.py", "1" ]
  - name: hello-world-2
    image: "ubuntu:14.04"
    env:
    - name: MESSAGE
      value: "hello world"
        command: [ "python" ]
        args: [ "./main.py", "2" ]
  - name: hello-world-3
    image: "ubuntu:14.04"
    env:
    - name: MESSAGE
      value: "hello world"
        command: [ "python" ]
        args: [ "./main.py", "3" ]

  • Related