【问题标题】:How to execute a shell script using kubectl exec with arguments [closed]如何使用带有参数的 kubectl exec 执行 shell 脚本 [关闭]
【发布时间】:2021-03-04 10:54:11
【问题描述】:

您好,我有一个名为 test.sh 的 shell 脚本。它需要两个参数 --a --b。我想使用 kubectl exec 执行它

我目前正在关注 kubectl exec pod-name -- path-to-shell-file ["Arguments"]

如果我在没有参数的情况下尝试它,shell 工作正常。

但这不起作用。

你们能帮帮我吗?

【问题讨论】:

    标签: shell kubernetes kubectl


    【解决方案1】:

    我认为kubectl exec pod-name -- shell-bin shell-script-path --a --b 应该可以。例如kubectl exec pod-name -- /bin/bash /path_to/test.sh --a --b。您遇到什么错误?

    编辑

    添加一个工作示例

     ~ $ kubectl exec nginx-deployment-7c8f47687f-b5qmw -- cat /test.sh
    echo The arguments for test.sh are $@
    
     ~ $ kubectl exec nginx-deployment-7c8f47687f-b5qmw -- /bin/bash /test.sh --a --b
    The arguments for test.sh are --a --b
    

    【讨论】:

    • 嗨 Syam Sankar 我收到未知参数错误 --a 参数被作为 kubectl 命令的一部分。
    • @Sabarinathan 我在答案部分添加了一个工作示例作为编辑。为了回答您的案例具体发生了什么,您能否分享您正在执行的实际命令、日志和脚本的源代码。
    猜你喜欢
    • 2021-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    相关资源
    最近更新 更多