<p>My question is simple.</p>
<p>How to execute a bash command in the pod? I want to do everything with a single bash command.</p>
<pre><code>[root@master ~]# kubectl exec -it --namespace=&quot;tools&quot; mongo-pod --bash -c &quot;mongo&quot;
Error: unknown flag: --bash
</code></pre>
<p>So, the command is simply ignored.</p>
<pre><code>[root@master ~]# kubectl exec -it --namespace=&quot;tools&quot; mongo-pod bash -c &quot;mongo&quot;
root@mongo-deployment-78c87cb84-jkgxx:/# 
</code></pre>
<p>Or so.</p>
<pre><code>[root@master ~]# kubectl exec -it --namespace=&quot;tools&quot; mongo-pod bash mongo
Defaulting container name to mongo.
Use 'kubectl describe pod/mongo-deployment-78c87cb84-jkgxx -n tools' to see all of the containers in this pod.
/usr/bin/mongo: /usr/bin/mongo: cannot execute binary file
command terminated with exit code 126
</code></pre>
<p>If it's just a bash, it certainly works. But I want to jump into the mongo shell immediatelly.</p>
<p>I found a solution, but it does not work. Tell me if this is possible now?
<a href="https://stackoverflow.com/questions/43499313/executing-multiple-commands-or-from-a-shell-script-in-a-kubernetes-pod">Executing multiple commands( or from a shell script) in a kubernetes pod</a></p>
<p>Thanks.</p>

JDev
<p>The double dash symbol &quot;--&quot; is used to separate the command you want to run inside the container from the kubectl arguments.
So the correct way is:</p>
<pre><code>kubectl exec -it --namespace=tools mongo-pod -- bash -c &quot;mongo&quot;
</code></pre>
<p>You forgot a space between &quot;--&quot; and &quot;bash&quot;.</p>
<p>To execute multiple commands you may want:</p>
<ul>
<li><p>to create a script and mount it as a volume in your pod and execute it</p>
</li>
<li><p>to launch a side container with the script and run it</p>
</li>
</ul>
