简体   繁体   English

在kubernetes pods容器中循环运行n次命令

[英]Running command in loop for n times inside kubernetes pods container

Basically, I need clarification if this is the right way to do: I am able to run sed command inside a container on a k8s pod. 基本上,我需要澄清这是否是正确的方法:我能够在k8s pod上的容器内运行sed命令。 Now, the same sed I want to loop over for 10times but am not sure if this is working though I get no error from kubernetes pods or logs. 现在,我想循环10次的同一个sed,但是我不确定从kubernetes容器或日志中没有收到任何错误,但这是否有效。 Please confirm if my looping is good. 请确认我的循环播放是否良好。

'sed -i "s/\(training:\).*/\1 12/" ghav/default_sql.spec.txt &&
         lant estimate -e dlav/lat/experiment_specs/default_sql.spec.txt -r /out'

I want to do this working command 10times inside the same container. 我想在同一个容器内执行10次此工作命令。 is the below right? 是下面的权利吗?

'for run in $(seq 1 10); do sed -i "s/\(training:\).*/\1 12/" ghav/default_sql.spec.txt &&
         lant estimate -e dlav/lat/experiment_specs/default_sql.spec.txt -r /out; done' 

the pod gets created and is running fine but am not sure how to confirm my loop is good and am doing that 10times... pod被创建并运行良好,但是不确定如何确认我的循环是否良好,并且正在执行10次...

inside pod describe I see below 里面的豆荚描述我在下面看到

Args:
  sh
  -c
  'for run in $(seq 1 10); do sed -i "s/\(training:\).*/\1 12/" ghav/default_sql.spec.txt &&
         lant estimate -e dlav/lat/experiment_specs/default_sql.spec.txt -r /out; done'

The " Define a Command and Arguments for a Container " does mention: 定义容器的命令和参数 ”确实提到:

To see the output of the command that ran in the container, view the logs from the Pod: 要查看在容器中运行的命令的输出,请查看Pod中的日志:

 kubectl logs command-demo 

So make sure that your command, for testing, does echo something, and check the pod logs. 因此,请确保您的命令(用于测试)确实回显某些内容,并检查Pod日志。

sh -c 'for run in $(seq 1 10); do echo "$run"; done'

As in: 如:

command: ["/bin/sh"]
args: ["-c", "for run in $(seq 1 10); do echo \"$run\"; done"]

(using seq here, as mentioned in kubernetes issue 56631 ) (如kubernetes问题56631所述,在此使用seq

For any complex sequence of commands, mixing quotes, it is best to wrap that sequence in a script file , and call that executable file 10 tiles. 对于任何复杂的命令序列,混合使用引号,最好将该序列包装在脚本文件中 ,然后将该可执行文件调用10个磁贴。 The logs will confirm that the loop is executed 10 times. 日志将确认循环已执行10次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM