<p>I have a pod/deployment initially with one replica. <strong>The code in the pod contains a variable/counter of type int</strong>. Initially equals  one,  and then when I scale the deployment. I want the second pod replica to set that variable/counter to two only in the second replica (while the value remains one in the first), and similarly when I scale to three replicas {replica1:counter=1, replica2:counter=2, replica3:counter=3) etc...</p>
<p>Can you please suggest a simple way to achieve the above if that is possible?</p>

<p>You can use the stateful sets if no issue with it, as it manages the sequence so.</p>
<p>You can use the name of POD as an environment so this, as stateful set will scale up it, will have a name as a variable for <strong>int</strong> you might need to parse or slice it as per need.</p>
<pre><code>env:
  - name: MY_POD_NAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name
  - name: env0
    value: value
</code></pre>
<p>Readmore at : <a href="https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/</a></p>
