【发布时间】:2021-11-21 16:52:06
【问题描述】:
我正在尝试使用 bash 脚本自动执行这些步骤
-
运行命令以访问程序的 shell(Kubernetes pod 的 bash shell)
kubectl exec --stdin --tty hello-node-7567d9fdc9-zvz55 -- bash -
在这个 shell 中,运行第二个命令(例如
python)root@hello-node-7567d9fdc9-zvz55:/# python Python 3.7.4 (default, Aug 13 2019, 15:17:50) [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> -
保持 shell 在前台打开/运行(这样用户可以立即将更多命令输入到步骤 2 中启动的 python shell)
我可以使用下面的脚本完成上述第一步。第二步和第三步怎么做?
#! /bin/bash
bash -c 'kubectl exec --stdin --tty hello-node-7567d9fdc9-zvz55 -- bash'
【问题讨论】:
-
你需要写一个
pexpect脚本 -
或者使用
python -c 'print("hello from python"); print ("hi")'提供多个python命令 -
你可以试试run individual commands in a pod,也可以试试这个answer。
-
您可以将
bash -c 'kubectl …'替换为kubectl …:绝对没有理由在您的shell 脚本中生成另一个 shell 进程。
标签: bash automation kubectl