Execute bash command in pod with kubectl?

后端 未结 2 1213
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 01:55

my question is simple.

How to execute a bash command in the pod? I want to do everything with one bash command?

[root@master ~]# kubectl exec -it --names         


        
2条回答
  •  清歌不尽
    2021-02-01 02:02

    The double dash symbol "--" is used to separate the arguments you want to pass to the command from the kubectl arguments. So the correct way is:

    kubectl exec -it --namespace=tools mongo-pod -- bash -c "mongo"
    

    You forgot a space between "--" and "bash".

    To execute multiple commands you may want:

    • to create a script and mount it as a volume in your pod and execute it

    • to launch a side container with the script and run it

提交回复
热议问题