<p>I have a pod running in kubernetes and i need to run two commands in one line.</p>

<p>Say,</p>

<pre><code>kubectl exec -it &lt;pod name&gt; -n &lt;namespace &gt; -- bash -c redis-cli
</code></pre>

<p>above command will open redis-cli</p>

<p>i want to run one more command after exec in one line ie info, i am trying below which is not working:</p>

<pre><code>kubectl exec -it &lt;pod name&gt; -n &lt;namespace &gt; -- bash -c redis-cli -- info
</code></pre>

Sanath Rai
<p><strong>You have to put your command and all the parameters between apostrophes.</strong></p>

<p>in your example it would be:</p>

<pre><code>kubectl exec -it &lt;pod_name&gt; -n &lt;namespace&gt; -- bash -c 'redis-cli info'
</code></pre>

<blockquote>
  <p><strong>From <code>Bash manual</code>: bash -c:</strong> If the -c option is present, then commands are read from the first non-option argument commaqnd_string.</p>
</blockquote>

<p><strong>Other option <em>(which in my opinion is a better approach)</em> is to get the output from the command with an instant pod, which creates, runs and deletes the pod right after that, like this:</strong></p>

<pre><code>kubectl run --namespace &lt;YOUR_NAMESPACE&gt; &lt;TEMP_RANDOM_POD_NAME&gt; --rm --tty -i --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --image docker.io/bitnami/redis:5.0.7-debian-10-r0 -- bash -c 'redis-cli -h redis-master -a $REDIS_PASSWORD info'
</code></pre>

<p><em>in my case the password was stored in a envvar called $REDIS_PASSWORD and I'm connecting to a server in a pod called redis-master.
I let it as I runned it to show that you can use as much parameters as needed.</em></p>

<p>POC:</p>

<pre><code>user@minikube:~$ kubectl run --namespace default redis-1580466120-client --rm --tty -i --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --image docker.io/bitnami/redis:5.0.7-debian-10-r0 -- bash -c 'redis-cli -h redis-master -a $REDIS_PASSWORD info'
 10:41:10.65 
 10:41:10.66 Welcome to the Bitnami redis container
 10:41:10.66 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-redis
 10:41:10.66 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-redis/issues
 10:41:10.67 Send us your feedback at containers@bitnami.com
 10:41:10.67 

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Server
redis_version:5.0.7
redis_git_sha1:00000000
redis_git_dirty:0
...
{{{suppressed output}}}
...
# CPU
used_cpu_sys:1.622434
used_cpu_user:1.313600
used_cpu_sys_children:0.013942
used_cpu_user_children:0.008014

# Cluster
cluster_enabled:0

# Keyspace
pod "redis-1580466120-client" deleted

</code></pre>
