2

I am on Kubernetes. I need to be able to write and run cron jobs in a pod. I can't use the CronJob workload. The solution I found is to run cron jobs from a cron sidecar container. I write cron jobs to /etc/crontab and run them with chroot. Although, I can run chroot commands from the command line, it doesn't seem to work as a cron job.

Example: This works when I run it in the shell.

# chroot /proc/151/root bash -c 'echo $(date) this is a command executed in cron sidecar >> /proc/151/root/var/log/cronjob.log' 

cronjob.log: Mon Apr 14 15:44:34 UTC 2025 this is a command executed in cron sidecar

Doesn't work when I put this line in /etc/crontab in cron sidecar container.

* * * * * root chroot /proc/151/root bash -c 'echo $(date) this is a cron job executed by cron sidecar >> /proc/151/root/var/log/cronjob.log' 

crond is running.

# pgrep cron 347 

What's wrong with this cron job? How can I make this work?

1 Answer 1

2

Use absolute paths for all executables and files in your cron job. Cron may not have the same PATH as your shell. Modify your cron job to:

* * * * * root /usr/sbin/chroot /proc/151/root /bin/bash -c '/bin/echo $(/bin/date) this is a cron job executed by cron sidecar >> /var/log/cronjob.log' 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.