<p>I am fairly new to kubernetes. Wanted to know if a program running inside a pod can access the namespace in which the pod is running.</p>
<p>Let me explain my usecase. There are two pods in my application's namespace. One pod has to be statefulset and must have atleast 3 replicas. Other pod (say POD-A) can be just a normal deployment. Now POD-A needs to talk to a particular instance of the statefulset. I read in an article that it can be done using this address format -
<code>&lt;StatefulSet&gt;-&lt;Ordinal&gt;.&lt;Service&gt;.&lt;Namespace&gt;.svc.cluster.local</code>.
In my application, the namespace part changes dynamically with each deployment. So can this value be read dynamically from a program running inside a pod?</p>
<p>Please help me if I have misunderstood something here. Any alternate/simpler solutions are also welcome. Thanks in advance!</p>

aniztar
<p><a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api</a> has an example of this and more.</p>
<pre><code>    env:
    - name: MY_POD_NAMESPACE
      valueFrom:
        fieldRef:
          fieldPath: metadata.namespace
</code></pre>
