<p>I have n instances of my micro-service running as kubernetes pods but as there's some scheduling logic in the application code, I would like only one of these pods to execute the code.</p>

<p>In Spring applications, a common approach is to activate <strong>scheduled</strong> profile <code>-Dspring.profiles.active=scheduled</code> for only instance &amp; leave it deactivated for the remaining instances. I'd like to know how one can accomplish this in kubernetes. </p>

<hr>

<p><strong>Note:</strong> I am familiar with the approach where a kubernetes cron job can invoke an end point so that only one instances picked by load balancer executes the scheduled code. However, I would like to know if it's possible to configure kubernetes specification in such a way that only one pod has an environment variable set.</p>

<p>You can create deployment with 1 replica with the required environment variable and another deployment with as many replicas you want without that variable. You may also set the same labels on both deployments so that Service can load balance traffic between pods from both deployments if you need it. </p>
