<p>My container code needs to know in which environment it is running on GKE, more specifically what cluster and project. In standard kubernetes, this could be retrieved from current-context value (<code>gke_&lt;project&gt;_&lt;cluster&gt;</code>).</p>
<p>Kubernetes has a downward api that can push pod info to containers - see <a href="https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/</a> - but unfortunately nothing from &quot;higher&quot; entities.</p>
<p>Any thoughts on how this can be achieved ?</p>
<p>Obviously I do not want to explicit push any info at deployment (e.g. as <code>env</code> in the <code>configMap</code>). I rather deploy using a generic/common yaml and have the code at runtime retrieve the info from env or file and branch accordingly.</p>

<p>You can query the <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#gke_mds" rel="nofollow noreferrer">GKE metadata server</a> from within your code.  In your case, you'd want to query the <code>/computeMetadata/v1/instance/attributes/cluster-name</code> and <code>/computeMetadata/v1/project/project-id</code> endpoints to get the cluster and project.  The client libraries for each supported language all have simple wrappers for accessing the metadata API as well.</p>
