从kubernetes运行多个python脚本

hs1rzwqc  于 2022-11-02  发布在  Kubernetes
关注(0)|答案(2)|浏览(191)

我想运行多个python脚本,并将参数传递给python脚本,我怎么能做到呢?在Kubernetes中可以吗?
就像我有多个python脚本,输入不同:"./main.py", "1" , "./main2.py", "2", "./main3.py", "3"我不能把它们都放在一个文件中运行,需要在这里分别运行它们,有没有办法做到这一点?

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" ]
tv6aics1

tv6aics11#

你能尝试如下所示

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" ]
vawmfj5a

vawmfj5a2#

在一个容器中只能有一个入口点......如果你想运行多个这样的命令,把bash作为入口点,把所有其他命令都作为bash运行的参数:

command: ["/bin/bash","-c","python ./main.py 1 && python ./main.py 2 && python ./main.py 3"]

也可以在一个窗格中运行多个container:

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" ]

相关问题