Kubernetes - Get Node Label from Container

7/14/2020

Is there any way to get a node labels from within a container for use as an environment variable?

It's similar to this https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/, but I need to use a label from the node for injecting into the container instead.

Thanks in advance!

-- wclim
kubernetes

1 Answer

7/14/2020

You will not be able to get node labels without sending some requests to the k8s api server. You could do that - but that would mean every pod will need read access and that's not great security wise.

How about an alternate solution - if you need to make sure the pod is running on nodes with specific labels, you can use taints and tolerations to achieve that more easily.

-- Yaron Idan
Source: StackOverflow