We’re in the process of transitioning a Laravel application to Kubernetes using EKS and k9s. For the most part, the application seems to be a good fit. However, we’ve run into a challenge related to the Laravel scheduler.
- Our Laravel application has a scheduler that relies on a cron job:
php artisan scheduler:run.
- The scheduled jobs are not idempotent. This means that missing a job or running the same job multiple times could have serious negative impacts.
- Stopping a job midway is equally problematic.
- Due to business constraints and associated costs, any meaningful revising the code to change this behavior isn’t an option. We need to migrate with the code as it is or with minimal and safe changes.
- Kubernetes’ CronJob feature isn’t a viable solution because it requires jobs to be idempotent. We verified this in the official documentation.
- Our current workaround involves using a persistent EC2 instance outside of EKS. Instead of running
php artisan scheduler:run, we execute
docker run "php artisan scheduler:run..."via a cron job on this EC2. While this provides a reasonable compromise, it has drawbacks.
- Our main dissatisfaction is that part of the application now sits outside the EKS cluster. This demands a different CI/CD approach, additional access maintenance, and, fundamentally, a bifurcated infrastructure.
I’m seeking alternative solutions or best practices that could help us:
- Maintain the non-idempotent nature of our jobs.
- Keep our infrastructure uniform and managed within the EKS cluster.
- Ensure the safe and reliable execution of our Laravel scheduler.
Any suggestions or insights on how we can tackle this would be greatly appreciated! Alternatively, reassurance that our present approach is the most prudent given our constraints would be equally valued.