Globally assign per-pod UUID/unique-ID for all pods

6/4/2019

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?

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 "assets" they make accessible to the cluster. The pods are expected to "clean up" 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.

Even if I use a pre-stop hook, 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.

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.


Question(s):

  1. 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).
  2. 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?
-- Cloud
hook
kubernetes
memory-management
postmortem-debugging
uuid

2 Answers

6/5/2019

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

It is also exposed to pod by env var, but make sure your kubernetes contain this commit.

-- menya
Source: StackOverflow

6/5/2019

you should be using Statefulsets for running stateful containers such as databases and not deployment. you will have control over the pod names like db-0, db-1, db-2

-- P Ekambaram
Source: StackOverflow