<p>I'm trying to write a little shell script that is checking the log output of a long running Kubernetes Pod when the Pod is done.</p>
<p>The script shall wait for status &quot;Completed&quot; but the following command does not exit when the status is switching from &quot;Running&quot; to &quot;Completed&quot;:</p>
<blockquote>
<p>$ kubectl wait --for=condition=Completed --timeout=24h pod/longrunningpodname</p>
<p>^C</p>
<p>$ kubectl get pods</p>
<p>NAME                               READY   STATUS      RESTARTS   AGE</p>
<p>longrunningpodname                 0/1     Completed   0          18h</p>
</blockquote>
<p>I would also expect the command to return immediately if the Pod is already in the status. But that doesn't happen.</p>
<p>Is kubectl wait not the command I'm looking for?</p>

Simon
<p>The use of bare pods is not the best approach to run commands that must finish. Consider using a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/" rel="noreferrer">Job Controller</a>:</p>

<blockquote>
  <p>A Job creates one or more Pods and ensures that a specified number of
  them successfully terminate. As pods successfully complete, the Job
  tracks the successful completions.</p>
</blockquote>

<p>Then, you can wait for the job condition:<br>
<code>kubectl wait --for=condition=complete --timeout=24h job/longrunningjobname</code></p>
