<p>I'm working with microservices in Java Spring MVC. With Kubernetes, the pods containing this microservice application logic can scale/replicate based on incoming load. In few words, there can be 2 or more copies of my application running.</p>

<p>I require to have a specific identifier mechanism which describes the specific pod replica / container containing the application. I was thinking to generate a random number as a descriptor at runtime and store it as an identifier to the container. But I was wondering if there is a better way, considering that I am working with Spring, TomCat and Kubernetes, I would expect that some of this tech stack can do something like this for me?</p>

Zeruno
<p>Kubernetes can do this. Each Pod will have a unique name that you can access as the hostname or through an environment variable. If you use a standard Deployment resource though this can change if the Pod dies and is recreated. It sounds to me like you want a StatefulSet, in which Pods are assigned unique ordinal indexes and retain these when recreated - <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#pod-identity" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#pod-identity</a></p>
