<p>Let's suppose a K8s cluster exists with a deployment with 3 replicas (shouldn't be relevant, but let's suppose it is an AKS cluster).</p>
<p>The container runs .NET 6 code with the K8s .NET client library. We can read the host pod id, but can we read the host pod replica number?</p>
<p>For example, let's suppose the 3 replicas are hosted in pods named podA, podB, podC.
Then podB crashes. K8s will restart the replica but with a different pod name, let's say podD.
How can I find, programmatically, that the just started pod is exactly the resuscitated podB?</p>

Franco Tiveron
<p>First of all, When a pod crashes, k8s doesn't necessarily change the name of the pod, Because as you said, it's restarted, not recreated. Restart will appear and number will increase incrementally in <code>RESTARTS</code> column of <code>kubectl get pods -n &lt;namespace&gt;</code> command output. If every restart would create a new pod, there would not have been necessary to have <code>RESTARTS</code> column in the first place.</p>
<p>Second, in your example, there is no way to assign <code>PodB</code>'s totally random name to <code>PodD</code> in deployment. Because k8s assigning them to deployment pods randomly. If you want to accomplish this, you should use <code>StatefulSet</code> instead of <code>Deployment</code> Because each pod in a StatefulSet has a unique and stable network identity.</p>
<p>As k8s document points ;</p>
<p><code>Like a Deployment, a StatefulSet manages Pods that are based on an identical container spec. Unlike a Deployment, a StatefulSet maintains a sticky identity for each of their Pods. These pods are created from the same spec, but are not interchangeable: each has a persistent identifier that it maintains across any rescheduling.</code></p>
<p>Reference : <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/</a></p>
