<p>I'm looking for a way to deploy a pod on kubernetes to run for a few hours each day. Essentially I want it to run every morning at 8AM and continue running until about 5:30 PM. </p>

<p>I've been researching a lot and haven't found a way to deploy the pod with a specific timeframe in mind. I've found cron jobs, but that seems to be to be for pods that terminate themselves, whereas mine should be running constantly.</p>

<p>Is there any way to deploy my pod on kubernetes this way? Or should I just set up the pod itself to run its intended application based on its internal clock?</p>

jzeef
<p>According to the Kubernetes architecture, 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. When a specified number of successful completions is reached, the job itself is complete. </p>

<p>In simple words, Jobs run until completion or failure. That's why there is no option to schedule a Cron Job termination in Kubernetes.</p>

<p>In your case, you can start a Cron Job regularly and terminate it using one of the following options:</p>

<ol>
<li><p>A better way is to terminate a container by itself, so you can add such functionality to your application or use Cron. More information about how to add Cron to the Docker container, you can find <a href="https://stackoverflow.com/questions/37458287/how-to-run-a-cron-job-inside-a-docker-container">here</a>.</p></li>
<li><p>You can use another Cron Job to terminate your Cron Job. You need to run a command inside a Pod to find and delete a Pod related to your Job. For more information, you can look through this <a href="https://stackoverflow.com/questions/42642170/kubernetes-how-to-run-kubectl-commands-inside-a-container">link</a>. But it is not a good way, because your Cron Job will always have <code>failed</code> status.</p></li>
</ol>

<p>In both cases, you need to check with what  status your Cron Job was finished and use the correct <code>RestartPolicy</code> accordingly.</p>
