<p>I'd like to get the current GKE project id from within one of its clusters via the Java client or the GCloud API itself.</p>

<ul>
<li>I'm running java containers in a GKE cluster of a specific Google Cloud project</li>
<li>I initialize the <code>ClusterManagerClient</code> with the appropriate <code>ClusterManagerSettings</code></li>
</ul>

<p>-> Is it possible to fetch this specific project id with this client?</p>

<p>(I'm expecting that there would be a global context within each GKE cluster where we could know the current project we're running on).</p>

<p>Thank you</p>

<p>As John Hanley mentioned in his comment above, you can use the instance metadata on the node in your cluster to determine the project that the node is a part of. The easiest way to see it is to use curl from a shell (either on the node or in a container).</p>

<p>If you want the project name, it can be seen at:</p>

<pre><code>curl "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google"
</code></pre>

<p>And if you want the project number, it can be seen at:</p>

<pre><code>curl "http://metadata.google.internal/computeMetadata/v1/project/numeric-project-id" -H "Metadata-Flavor: Google"
</code></pre>

<p>This isn't part of the container API surface, so the <code>ClusterManagerClient</code> isn't the right API client to use. You need to create a client to fetch the instance metadata, which I would expect might be part of the compute client libraries, or you can just make a local HTTP request if you add the right headers (as shown above) since you don't need any special client authentication / authorization to access the local metadata. </p>
