<p>I am running Node JS with Express JS in Kubernetes cluster as service using Deployment YML file with 2 replicas. I am using HELM for deployment.</p>
<p>Now I am having the requirement to execute the scheduler to run a particular task at a given interval.</p>
<p>If I am running it as single instance, I can implement within the same service, but since I am using replicas, the scheduler will be run in two different pods at same time.</p>
<p>Is there a way to configure such that I can run the scheduler in a single pod and disable it in another pod of the same Node JS service?</p>
<p>Or do I want to move as a separate Node JS service and maintain it?</p>
<p>Can you please provide your suggestion?</p>

<p>In Kubernetes, you can find an Object named <a href="https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/" rel="nofollow noreferrer">CronJob</a>.</p>
<p>This will achieve a scheduler role, as a Linux cron would.</p>
<p>You can use the same image as your express JS app, but start a different script that will exit with a code at the end.</p>
<p>Example:</p>
<p><code>node app.js</code> starts your express server</p>
<p><code>node schedule.js</code> starts your cron task</p>
<p>Best,</p>
