<p>I would like to access to OpenShift and Kubernetes API from inside a pod to query and modify objects in the application the pod belongs to.</p>

<p>In the documentation (<a href="https://docs.openshift.org/latest/dev_guide/service_accounts.html" rel="noreferrer">https://docs.openshift.org/latest/dev_guide/service_accounts.html</a>) I found this description on how to access the api:</p>

<pre><code>$ TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)"

$ curl --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \
"https://openshift.default.svc.cluster.local/oapi/v1/users/~" \
-H "Authorization: Bearer $TOKEN"
</code></pre>

<p>The problem is when I for example want to access a pod, I need to know the namespace I'm in:</p>

<p><code>https://openshift.default.svc.cluster.local/oapi/v1/namespaces/${namespace}/pods</code></p>

<p>The only way I found so far is to submit the namespace as an environment variable, but I would like to not requiring the user to enter that information.</p>

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