Executing multiple commands( or from a shell script) in a kubernetes pod

后端 未结 3 2198
生来不讨喜
生来不讨喜 2020-12-18 21:11

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

below is my sample_script.sh

kubect

3条回答
  •  星月不相逢
    2020-12-18 21:40

    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.

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

    Try running this:

    $ 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"
    

提交回复
热议问题