Execute bash command in pod with kubectl?

I use something like this to get into the pod's shell:

    kubectl exec -it --namespace develop pod-name bash

then you can execute the command you want within the pod (e.g. ping)

    ping www.google.com

then you can see your ping log and voila ... enjoy it :D


The double dash symbol "--" is used to separate the command you want to run inside the container 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