<p>I am retrieving a list of Clusters from GKE using <strong>GKE Rest API</strong>. Next, I need to retrieve containers information from <strong>Kubernetes API Server</strong> for a particular GKE cluster. There are two authentication methods known to me which can be used to authenticate a cluster with Kubernetes API. First One is Basic Authentication and the second one is Authentication using client certificate and client key. I have found out <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/api-server-authentication#legacy-auth" rel="nofollow noreferrer">Here</a> that both of these approaches are no more recommended.</p>
<p>My question is that what other authentication method I can use to authenticate my GKE cluster with Kubernetes API using its Java client library.</p>

Jawad Tariq
<p>The java client should be able to find the pod's service account and authenticate itself within a cluster, and use a kubeconfig file to authenticate when outside cluster.  The default location to look for a kubeconfig file is <a href="https://github.com/kubernetes-client/java/blob/master/util/src/main/java/io/kubernetes/client/util/KubeConfig.java#L48-L50" rel="nofollow noreferrer"><code>HOME/.kube/config</code></a></p>
<p>When outside the cluster, the <a href="https://cloud.google.com/sdk/gcloud/reference/container/clusters/get-credentials" rel="nofollow noreferrer"><code>gcloud container clusters get-credentials ...</code></a> command will create a kubeconfig file with proper helper configuration to authenticate.  Presumably there is a java way to set up a kubeconfig file without running gcloud from a shell in the <a href="https://googleapis.dev/java/google-cloud-container/latest/" rel="nofollow noreferrer">google-cloud-container</a> library.</p>
