在 kubernetes pod 中执行多个命令(或从 shell 脚本) [英] Executing multiple commands( or from a shell script) in a kubernetes pod

查看:316
本文介绍了在 kubernetes pod 中执行多个命令(或从 shell 脚本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 shell 脚本,它需要登录到 pod 并在 kubernetes pod 中执行一系列命令.

I'm writing a shell script which needs to login into the pod and execute a series of commands in a kubernetes pod.

下面是我的sample_script.sh:

Below is my sample_script.sh:

kubectl exec octavia-api-worker-pod-test -c octavia-api bash
unset http_proxy https_proxy
mv /usr/local/etc/octavia/octavia.conf /usr/local/etc/octavia/octavia.conf-orig
/usr/local/bin/octavia-db-manage --config-file /usr/local/etc/octavia/octavia.conf upgrade head

运行这个脚本后,我没有得到任何输出.任何帮助将不胜感激

After running this script, I'm not getting any output. Any help will be greatly appreciated

推荐答案

您是否将所有这些命令作为单行命令运行?首先,这些命令之间没有 ;&& .因此,如果您将其作为多行脚本粘贴到您的终端中,它很可能会在本地执行.

Are you running all these commands as a single line command? First of all, there's no ; or && between those commands. So if you paste it as a multi-line script to your terminal, likely it will get executed locally.

其次,要告诉 bash 执行某事,您需要:bash -c "command".

Second, to tell bash to execute something, you need: bash -c "command".

试试运行这个:

$ kubectl exec POD_NAME -- bash -c "date && echo 1"

Wed Apr 19 19:29:25 UTC 2017
1

你可以像这样使它成为多行:

You can make it multiline like this:

$ kubectl exec POD_NAME -- bash -c "date && 
      echo 1 && 
      echo 2"

这篇关于在 kubernetes pod 中执行多个命令(或从 shell 脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆