<p>Is there a UUID attribute (or something similar) that is either automatically assigned to all K8S pods, or that can be globally configured for a cluster?</p>
<p>I have an application that acts as a database (DB) front-end in my cluster, where some (but not all pods) submit a catalog of digital &quot;assets&quot; they make accessible to the cluster. The pods are expected to &quot;clean up&quot; their entries they created in the DB before shutting down, but there are cases where the pods could crash, preventing the shutdown/cleanup code from executing.</p>
<p>Even if I <a href="https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-terminating-with-grace" rel="nofollow noreferrer">use a pre-stop hook</a>, the pod has already crashed, and I can no longer access data within it to know what assets it has reported to the DB application.</p>
<p>I was considering having the DB application, upon receiving an incoming connection, query the remote pod for IP, unique ID/UUID of some sort, etc.; and map that data to the DB information submitted by the pod. I can then have the DB application periodically poll the cluster via the K8S REST API to see if a pod with the corresponding UUID still exists, and to clear out individual records if the pod-UUID associated with them is no longer present.</p>
<hr />
<h1>Question(s):</h1>
<ol>
<li>Is there a way to automatically assign such a UUID to all pods in the cluster at a global level (i.e. without having to modify the YAML files for all my pods, deployments, etc).</li>
<li>Is there some other K8S-supplied mechanism/feature that would provide a better means of post-mortem cleanup of pod resources that live in a separate/external pod?</li>
</ol>

<p>You can access pod's uid by <code>kubectl get pods/$POD_NAME -o yaml</code>, it is under <code>metadata.uid</code>.</p>

<p>It is also exposed to pod by <a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/" rel="nofollow noreferrer">env var</a>, but make sure your kubernetes contain this <a href="https://github.com/kubernetes/kubernetes/commit/0f65b218a07e3a5edda16484604dcf1f76bae793" rel="nofollow noreferrer">commit</a>.</p>
