<p>I am creating</p>
<ul>
<li>A pod every two minutes using cron-job</li>
<li>It has custom python image that reads the data from redis</li>
</ul>
<p>The problem is, it keeps on creating pods every two minutes irrespective of others terminated or not, I am trying to terminate the pod, if I get a response like &quot;Empty&quot; from the pod, the operation that is running in the pod, gives the response like that, if it doesn't give response like this, I want to terminate within 10 sec.</p>

shivaniverma6991
<p>You can do something like</p>
<pre><code>kubectl wait --for=condition=complete job/jobname
</code></pre>
<p>and you can also set a timeout:</p>
<pre><code>kubectl wait --for=condition=complete --timeout=10s job/jobname
</code></pre>
<p>Example python script that will be checking the redis</p>
<pre><code>#!/usr/bin/env python

import time
import rediswq

host=&quot;redis&quot;
# Uncomment next two lines if you do not have Kube-DNS working.
# import os
# host = os.getenv(&quot;REDIS_SERVICE_HOST&quot;)

q = rediswq.RedisWQ(name=&quot;job2&quot;, host=host)
print(&quot;Worker with sessionID: &quot; +  q.sessionID())
print(&quot;Initial queue state: empty=&quot; + str(q.empty()))
while not q.empty():
  item = q.lease(lease_secs=10, block=True, timeout=2) 
  if item is not None:
    itemstr = item.decode(&quot;utf-8&quot;)
    print(&quot;Working on &quot; + itemstr)
    time.sleep(10) # Put your actual work here instead of sleep.
    q.complete(item)
  else:
    print(&quot;Waiting for work&quot;)
print(&quot;Queue empty, exiting&quot;)
</code></pre>
<p>ref : <a href="https://kubernetes.io/docs/tasks/job/fine-parallel-processing-work-queue/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/job/fine-parallel-processing-work-queue/</a></p>
