<p>I have a general question in optimization in having multiple Kubernetes pods. I have a Java application <code>service A</code> which checks on <code>service B</code> every 5 mins for a condition to do <code>task T</code>. Every 5 mins, if the condition is met, I want <code>task T</code> to be run.</p>
<p>However, <code>service A</code> currently run with 4 pods, and each of them are checking <code>service B</code> separately, and performing <code>task T</code> if condition is met. But the <code>task T</code> needs only to be performed one time if the condition on <code>service B</code> is met.</p>
<p>I am wondering if there's a way for different pods of <code>service A</code> to coordinate and only do <code>task T</code> one time every 5 mins (if condition is true), instead of 4 times done by each pod.</p>
<p>Thank you!</p>

Dyson
<p>May I ask why is it necessary for you to run this apparently periodic service with a 4 pod deployment?</p>
<p>A better idea would be to use a <code>CronJob</code> instead that runs every 5 minutes and performs the task you want it to. Every time the <code>CronJob</code> is to run it will spawn a pod, which will check the condition on <code>Service B</code>, run the task if needed and decommission itself.</p>
<p>I don't see why you want to have 4 pods of a service that is basically a cron job.</p>
<p>You can find details on <code>CronJobs</code> <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="noreferrer">here</a>.</p>
