一般情况下,k8s 在 Job 或 CronJob 中只需要写入简单的 shell 命令,而对于需要执行脚本的话,需要将 脚本 挂载到configMap中,然后将其挂载到 volume 上,然后执行 xxxx.sh
但是对于介于一两行和复杂的shell 之间采用多行方式执行,以下介绍三种:
1,种
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
restartPolicy: Never
containers:
- name: my-container
image: "ubuntu:14.04"
command: ["/bin/sh","-c"]
args: ["command one; command two && command three"]
2,种
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
restartPolicy: Never
containers:
- name: my-container
image: "ubuntu:14.04"
command: ["/bin/sh","-c"] # sh /etc/kibana.sh
args:
- |
echo hello
i=0
while ((i<5))
do
echo hello${i}
i=$((i+1))
done
在go程序中相应的为:
其中 :