gpt4 book ai didi

yaml - 如何使用Kubernetes在一个Yaml文件中设置多个命令?

转载 作者:行者123 更新时间:2023-12-02 12:26:50 25 4
gpt4 key购买 nike

在此官方文档中,它可以在yaml配置文件中运行命令:

https://kubernetes.io/docs/tasks/configure-pod-container/


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

如果我要运行多个命令,该怎么办?

最佳答案

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

说明: command ["/bin/sh", "-c"]说“运行 shell 程序,并执行以下指令”。然后将args作为命令传递到 shell 。在shell脚本中,用分号分隔命令,如果第一个成功, &&有条件地运行以下命令。在上面的示例中,它总是先运行 command one,然后再运行 command two,并且仅在 command three成功的情况下运行 command two

替代方法:在许多情况下,您要运行的某些命令可能设置了要运行的最终命令。在这种情况下,构建自己的 Dockerfile是必经之路。特别要看 RUN指令。

关于yaml - 如何使用Kubernetes在一个Yaml文件中设置多个命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62799311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com