How to get the namespace from inside a pod in OpenShift? How to get the namespace from inside a pod in OpenShift? kubernetes kubernetes

How to get the namespace from inside a pod in OpenShift?


At least in kubernetes 1.5.3 I can also see the namespace in /var/run/secrets/kubernetes.io/serviceaccount/namespace.


You can get the namespace of your pod automatically populated as an environment variable using the downward API.


I found a solution by tracing what the web console does.

I am allowed to ask for the project list without having cluster-admin rigths on the following url:

https://openshift.default.svc.cluster.local/oapi/v1/projects

Only the projects which I have rights to are listed, and then it is possible to determine the current project which name is also the namespace.

Would love if there was an easier solution, but this works.