I'm building a microservices application using Kubernetes as a containers orchestrator. The app is up and running now but i have an other issue. That is in my services, i have a scheduled task running daily and when service get deployed, multiple service instances will run (by set replica number), that created multiple tasks running at the same time. What i expect is only ONE instance of service task will be running rather than multiple. Is there any technique to handle this case?
Please help me with this, Thanks!
You have 2 ways of solving this problem:
1) Use task coordination in your application. Like there is a lock and only application owning a lock can run task. Take a look towards ZooKeeper for a distributed lock logic. This is the preferred solution.
2) Use Kubernetes CronJob which runs daily.