<p>So have an OpenShift cluster and running a pod in the <code>mongodb-test</code> namespace. The pod is running fine</p>

<pre><code>$ kubectl get pods -n mongodb-test                                             
NAME               READY   STATUS      RESTARTS   AGE
mongodb-1-7ww9k    1/1     Running     0          14m

</code></pre>

<p>When I exec into the pod and run the <code>mongo</code> command, I dont get any issue and the command works as expected.</p>

<pre><code>$ kubectl exec -it -n mongodb-test  mongodb-1-7ww9k   -c mongodb  sh
sh-4.2$ mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
&gt; 
</code></pre>

<p>Now the problem is when I try to run the same command using below syntax I get <code>mongo</code> not found</p>

<pre><code>$ kubectl exec -it -n mongodb-test mongodb-1-7ww9k -c mongodb -- sh -c mongo
sh: mongo: command not found
E0227 13:02:01.728579   24237 v3.go:79] EOF
                                           command terminated with exit code 127
</code></pre>

<p>Below are the output of <code>echo $PATH</code> and <code>which mongo</code> from inside the pod.</p>

<pre><code>$ kubectl exec -ti -n mongodb-test mongodb-1-7ww9k -c mongodb -- sh 
sh-4.2$ echo $PATH
/opt/rh/rh-mongodb36/root/usr/bin:/opt/rh/rh-mongodb36/root/usr/sbin:/opt/app-root/src/bin:/opt/app-root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
sh-4.2$ which mongo
/opt/rh/rh-mongodb36/root/usr/bin/mongo
sh-4.2$ 

</code></pre>

<p>So, here is what the problem was. When I tried to execute <code>mongo</code> actually after getting inside the pod using the command </p>

<pre><code>$ kubectl exec -it -n mongodb-test  mongodb-1-7ww9k   -c mongodb  sh
</code></pre>

<p>somehow the path to where the <code>mongo</code> executable is was being set into <code>PATH</code> (through <code>.bash_profile</code> :confused), but when I tried to call <code>mongo</code>, using the below command, the same was not happening.</p>

<pre><code>kubectl exec -it -n mongodb-test mongodb-1-7ww9k -c mongodb -- sh -c mongo
</code></pre>

<p>Since we suspected the <code>PATH</code> was being set in <code>.bash_profile</code> I tried to execute <code>mongo</code> in bash and below command worked.</p>

<pre><code>kubectl exec -it -n mongodb-test mongodb-1-7ww9k -c mongodb -- bash -c mongo
</code></pre>
