POD needs to know its owner

Is there a way to reliably inject information about the POD’s owner (replica set, deployment, etc.) into the POD? So far I’ve only seen a recommendation to use Downward API to inject the value of POD’s kubernetes.io/created-by annotation, but (at least in my cluster) that doesn’t seem to be set by default, and I need something that will work reliably across a broad set of clusters. I wish I could get information from ownerReference, but from the description of Downward API that doesn’t seem possible. Is there a way?

I think there is no straightforward way.

If the info is there, though, and you have a good and generally useful use case, it might be easy to just add it to the downwards API (although not sure info is there and easy to access).

Wanna share more about your use case? :slight_smile:

It’s simple - I’m designing a monitoring solution for Kubernetes clusters, so I need to identify the source of telemetry somehow. Beyond the POD name/namespace (which is easy to get from the Downward API), I’d need a more stable identifier that lives through POD restarts. I’ll probably just default to the value of the app label, but it would be nice to have a fallback which works out of the box by default.

Hmm, wait, you are designing a monitoring solution and how it will run? Because the downwards API is used in the pod itself. Will you force a sidecar container in every pod, then?

It seems weird, I think.

If you are not doing that, or if you are using the kubernetes API (either running as a sidecar container or not), you can and should query for deployments, jobs, etc. And I guess if you are doing it, it might be a way to establish a relation between pods and deployments (if they are created for a deployment, of course).

About the more stable id, it really depends on what you want to model. The pod name is quite stable, but of course only for the pod lifecycle. It doesn’t change on pod restarts, though. Some monitoring solutions use that and, with labels filters and that stuff, is quite fine to do some charts with that :slight_smile: