<p>I am trying to write a python script using one of the sdk by my org, and extract some useful information from kubernetes pod.</p>
<p>The sdk I have has a podexec() function which can be used to execute a command inside the pod.</p>
<p>I have a specific usecase, where I've to execute a command inside of the pod, which inturn will spin up an interactive shell, and then in that interactive shell, I want to execute a command and print the output.</p>
<p>For example, Let's say there's a mysql pod, and I want to first exec into the mysql pod, and then run <strong>mysql</strong> command which will bring up an <em>interactive mysql shell</em>, where I want to enter some commands like &quot;<strong>Show tables;</strong>&quot;, and then get the output of that command in my script. Is it possible?</p>
<p>After getting into the pod, I am able to run a single command like below</p>
<pre><code>kubectl exec -it mysql-pod -- bash

echo &quot;show tables;&quot; |mysql
</code></pre>
<p>Now how to run this without entering the pod with just the kubectl?</p>
<p>NOTE: My usecase is not w.r.t mysql actually. My org has a custom tool which lets us execute commands in it's interactive shell. Mysql here is just an example.</p>

<p>Ok. Figured it out.</p>
<pre><code>kubectl exec -it mysql-pod -- bash -c &quot;echo \&quot;show tables\&quot; |mysql&quot;
</code></pre>
