2

I was trying to find a solution how to run a job handled by 2 pods in a cluster. The job is ran by the cronjob scheduler, to run every (say) 15 mins. This job is to fetch records from the db table and process it. There is only READ permission provided to access the table records. I am trying to see, is there any way to configure in k8s, that only one pod run the job. This way I want to prevent the duplicate processing. The alternate is have a temporary lock file in the persistent storage and the application in the pod puts a lock to it and releases after processing. If there is any out of box solution available with in k8s, please let me know.

Senthil
  • 323
  • 4
  • 15
  • If you have 2 pods to handle the job, but only 1 at a time can access db? Then you need some form of synchronization, yes. – Jonas Apr 28 '21 at 17:14

1 Answers1

0

This is implemented using a traditional resource lock mechanism. A lock file is created during the process and the pods do no run if there is any lock file exists. This way only one pods will run the job any point of time.

Senthil
  • 323
  • 4
  • 15