<p>For a multi zoned, multi cluster setup. Is it possible to dynamically expose or retrieve the zone in which the master node is running, from a pod? Since this is needed to correctly push our metrics to stackdriver, in order to run a <a href="https://github.com/GoogleCloudPlatform/k8s-stackdriver/tree/master/custom-metrics-stackdriver-adapter" rel="nofollow noreferrer">horizontal pod autoscaler</a> based on them.</p>

<p>I can hardcode it in the individual deployments but I would like to avoid that.</p>

<p>I've tried looking in the compute internal metadata endpoint, and in the <a href="https://stackoverflow.com/questions/47891326/way-to-get-list-of-field-references-in-kubernetes/47891675#47891675">reference variables</a> kubernetes has, but none seem to expose the zone of the master.</p>

<p>There is an unofficial way to determine what zone (or region) the master is running in by parsing the <code>kube-env</code> metadata entry on a node. <code>kube-env</code> is a key-value store where keys are all uppercase, followed by a colon, which is followed by the value. If you look for the key <code>ZONE</code> the value will be the cluster location (e.g. the master zone for multi-zonal clusters with a single zone master or the master region for regional clusters). </p>

<p>Note that this isn't a supported API, so it may disappear in future versions of GKE, but for now it's a simple way to fetch the cluster location from any node. </p>
