Hi I was trying to get pod zone/region information using environment variable inside container. I was able to get pod name using below config. Please help me to get zone/region information.
I think there is none for the node labels, but if the use case is really good and generally useful it can probably be added.
I see in that link that you have the nodeName. I don’t find the node labels. As a work around, maybe you can save the node names and regions and access that, or even use the kubernetes API (a service account to access it)
I dont want to make kubernetes API request. I want to get region/Zone information to be added to the application logs. So basically region/zone information should be made available on pod creation into environment variables. If something similar to Podname which I extracted is available it would be helpful.
I see there is a configMapref for envVar in the link u sepcified. Do you know any configMap which has mapping of Node to region/zone? which I could use since I know the nodename from Pod.
For sure there is no such a configmap created automatically. And, of course, that is dynamic in most environments, so it should be updated dynamically too.
Bob’s idea seem more appropriate if you really want that.
Can I ask what is the underlying issue you want to solve? The root? If that is it, okay, but if there is some other problem that you want to solve, there might be another way to tackle it besides having an env var with the region.
I just want region in logs. Underlying issue is to debug node/pod shutdowns based on region/Zone. since on pod/node restart nodename and pod Id changes, the only metadata independent of pod/Node restarts is region.
Yes, we could inject some agents as @mrbobbytables suggested which would pull node region/zone from kubernetes. But why should I use some third party agents since its a metadata of pod I would expect kubernetes to provide a way to access it.