How to get the current namespace in a Pod? How to get the current namespace in a Pod? kubernetes kubernetes

How to get the current namespace in a Pod?


Try the file:

/var/run/secrets/kubernetes.io/serviceaccount/namespace


you don't need to set a static namespace env variable in the pod spec if you want to use env variables, you can use the "Downward API" for letting k8s fill it dynamically with the current namespace. See https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api