<p>When we use <code>PM2</code> in cluster mode, we can find out the instance number inside node app using <code>process.env.NODE_APP_INSTANCE</code>, but how we can find that inside a kubernetes cluster without <code>pm2</code>. I'm looking for similar like find replica instance number or etc.</p>
<p>Imagine a node app with 2 or more replicas and we need to run <code>node-cron</code> scheduler only inside one of pods.</p>

<p>I found that when use <code>Statefulset</code> instead of the <code>Deployment</code> then it's possible to inject the determinable POD name as an environment variable.</p>
<pre><code>  ...
  containers:
     ...
     env:
     - name: &quot;POD_NAME&quot;
       valueFrom:
         fieldRef:
           fieldPath: metadata.name
</code></pre>
<p>And then <code>POD_NAME</code> variable has the value like this: pod-0 or pod-1 and so on.
So we can find out the instance number with that ordinal number.</p>
