Switching from CronJob to a Deployment that sleeps in a loop

Created: — modified: — tags: k8s

Has one benefit

You can easily trigger the job by killing the pod.

Just for clarification, your code looks like this:

while true; do

    # do your job

    sleep 1h $(( $RANDOM % 12 ))

done

It works like this: when pod starts - your job runs. Then it waits for 1 hour and runs your job again. If you need to trigger the job - you just kill the pod - it got recreated, and your job runs again. If you don't really care, when exactly the job runs - thing might be what you need.

$(( $RANDOM % 12 )) add little (up to 12 sec) jitter, so several jobs don't trigger at the same time