<p>I am using kubernetes java client libraries in order to communicate with my kubernetes server. </p>

<p>My question is there any way programmatically get namespace of running pod from inside of which sent call to kubernetes?</p>

<p>I heard that there is file located here - <strong>/var/run/secrets/kubernetes.io/serviceaccount/namespace</strong></p>

<p>However I wanted to know is there any way ro get it using java client without reading this file. </p>

<p>I have searched in documentation, however found nothing related to this.</p>

liotur
<p>If you set the below environment variable on the pod definition file, the namespace of the pod will be stored on the environment variables. Then it can be retrieved by the client API.</p>

<pre><code> env
  - name: MYPOD_NAMESPACE
      valueFrom:
        fieldRef:
          fieldPath: metadata.namespace
</code></pre>
