<p>I have a use case with elastic search for rack awareness, which requires me to identify the zone that a pod has been scheduled in.</p>

<p>I've seen many requests for this outside of SO, such as:</p>

<p><a href="https://github.com/kubernetes/kubernetes/issues/40610" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/40610</a></p>

<p>The zone is not exposed in the downward API due to it being a node label, not a pod label.</p>

<p>The two "answers" I have come up with are:</p>

<p>a) Curl request to the google metadata endpoint to retrieve the node from the compute engine metadata</p>

<p>b) Identify the node name via the downward API, and make a call to the Kube API with the node name to retrieve the node object, and use a tool such as JQ to filter the JSON response to get the zone. </p>

<p>I don't like option B due to it being more or less hardcoded against the API call, and I would need to provision a custom docker image with JQ and curl included. Option A feels a bit 'hacky' given it's not Kube native.</p>

<p>Are there any better solutions that I've missed?</p>

<p>Thanks in advance,</p>

dwillams782
<p>My case is Google Kubernetes Engine, and I needed to have zone/region labels on pods.</p>

<p>What i did was combined @dwillams782 approach in  <a href="https://stackoverflow.com/a/52428782/8547463">https://stackoverflow.com/a/52428782/8547463</a> of getting zone via </p>

<pre><code>curl -sS http://metadata.google.internal/computeMetadata/v1/instance/zone -H 'Metadata-Flavor: Google'`
</code></pre>

<p>and set it as labels to pods via approach in <a href="https://github.com/devth/k8s-labeler" rel="nofollow noreferrer">https://github.com/devth/k8s-labeler</a>. Basically i called the zone detection API from initContainer of pod.</p>
