Run Scheduled Cron method in Spring from single pod if multiple pods exist on Kubernetes Run Scheduled Cron method in Spring from single pod if multiple pods exist on Kubernetes kubernetes kubernetes

Run Scheduled Cron method in Spring from single pod if multiple pods exist on Kubernetes


You can use a quartz scheduler with JDBC store. This will take care of your requirement automatically.

In short: "Load-balancing occurs automatically, with each node of the cluster firing jobs as quickly as it can. When a trigger’s firing time occurs, the first node to acquire it (by placing a lock on it) is the node that will fire it."

Please refer to the official link for details- http://www.quartz-scheduler.org/documentation/quartz-2.3.0/configuration/ConfigJDBCJobStoreClustering.html


Also, you can move the workload to an isolated process, this will be helpful and cleaner, check this out https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ this will give you an idea.