I have a deployment of my backend app which has 6 replicas. In the code of the app, I have a node.js cronjob running every minute. But the problem is that because I have 6 replicas, it runs 6 times in parallel. I want to send env variable to exactly only one Pod in the deployment to ensure that only 1 Pod performs the cronjob. Then in the app code I will check this using the process.env.SHOULD_PROCESS_CRONJOBS == 1
.
If this is not the right way to achieve what I need, can you inform me on how to handle cronjobs using nodejs in distributed environment like K8S?