<p>I used to be able to curl </p>

<pre><code>https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1beta3/namespaces/default/
</code></pre>

<p>as my base URL, but in kubernetes 0.18.0 it gives me "unauthorized". The strange thing is that if I used the external IP address of the API machine (<code>http://172.17.8.101:8080/api/v1beta3/namespaces/default/</code>), it works just fine.</p>

<p>In the official documentation I found this: </p>

<p><a href="https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#accessing-the-api-from-a-pod" rel="noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#accessing-the-api-from-a-pod</a></p>

<p>Apparently I was missing a security token that I didn't need in a previous version of Kubernetes. From that, I devised what I think is a simpler solution than running a proxy or installing golang on my container. See this example that gets the information, from the api, for the current container:</p>

<pre><code>KUBE_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
      https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/default/pods/$HOSTNAME
</code></pre>

<p>I also use include a simple binary, jq (<a href="http://stedolan.github.io/jq/download/" rel="noreferrer">http://stedolan.github.io/jq/download/</a>), to parse the json for use in bash scripts.</p>
