<p>What I would like to do is to run some backup scripts on each of Kubernetes nodes periodically. I want it to run inside Kubernetes cluster in contrast to just adding script to each node's crontab. This is because I will store backup on the volume mounted to the node by Kubernetes. It differs from the configuration but it could be CIFS filesystem mounted by Flex plugin or <code>awsElasticBlockStore</code>.</p>

<p>It would be perfect if <code>CronJob</code> will be able to template <code>DaemonSet</code> (instead of fixing it as <code>jobTemplate</code>) and there will be possibility to set <code>DaemonSet</code> restart policy to <code>OnFailure</code>.</p>

<p>I would like to avoid defining <code>n</code> different <code>CronJobs</code> for each of <code>n</code> nodes and then associate them together by defining <code>nodeSelectors</code> since this will be not so convenient to maintain in environment where nodes count changes dynamically.</p>

<p>What I can see problem was discussed here without any clear conclusion: <a href="https://github.com/kubernetes/kubernetes/issues/36601" rel="noreferrer">https://github.com/kubernetes/kubernetes/issues/36601</a></p>

<p>Maybe do you have any hacks or tricks to achieve this?</p>

<p>You can use DaemonSet with the following bash script:</p>
<pre><code>  while :; do
   currenttime=$(date +%H:%M)
   if [[ &quot;$currenttime&quot; &gt; &quot;23:00&quot; ]] &amp;&amp; [[ &quot;$currenttime&quot; &lt; &quot;23:05&quot; ]]; then
     do_something
   else
     sleep 60
   fi
   test &quot;$?&quot; -gt 0 &amp;&amp; notify_failed_job
  done
</code></pre>
