<p>I have a redis DB server container in a microk8s cluster, and I'd like to keep a running instance of the client so that I can attach to it from time to time to talk to the server container.</p>
<p>In <a href="https://kubernetes.io/docs/tasks/job/fine-parallel-processing-work-queue/" rel="nofollow noreferrer">one official example</a>, the redis client is called interactively as follows:</p>
<pre><code>kubectl run -i --tty temp --image redis --command &quot;/bin/sh&quot;
</code></pre>
<p>and then, the user enters data or interacts with the server manually. But I need to do this repeatedly from a shell script. What I tried so far is something like:</p>
<pre><code>kubectl run -i temp --rm --image redis -- bash -c &quot;redis-cli -h redis LRANGE myqueue 0 -1 | cut -f 2- -d ' '&quot;
</code></pre>
<p>This works some times, but occasionally gives an error:</p>
<blockquote>
<p>error: timed out waiting for the condition</p>
</blockquote>
<p>I am not sure exactly what condition is being waited for, and I guess it may be related to the fact that a temporary container is created and immediately deleted when the job is done. But I don't necessarily want to repeatedly create and delete containers like this just to run a few shell commands each time. It's slow and now seems to produce unpredictable errors.</p>
<p><em>Is there a way in kubernetes to keep a running instance of the container (redis client here), and send bash commands to it via the pipeline or some other means, from time to time? (instead of deleting and recreating it)</em></p>

thor
<p>Try <code>kubectl run temp --image redis --command sleep infinity</code>. This will start a redis pod and enter sleep state. You can then use the pod to execute command like <code>kubectl exec -it temp -- redis-cli -h redis LRANGE myqueue 0 -1 | cut -f 2- -d ' '</code>. The pod will not exit upon command execution, it will only exit if you delete the pod.</p>
