<p>I have configured minikube in my local machine and going to use kubernetes externally. I have created a Service Account in kubernetes and using it's secret I can get the access token using below command.</p>

<pre><code>kubectl get secret &lt;service-account-secret&gt; -o yaml -n mynamespace
</code></pre>

<p>My question is how can I do this using fabric8 java client in runtime ? What I want is to obtain the access token by giving the secret of the Service account as a parameter.</p>

<p>I am initiating the config as bellow.</p>

<pre><code>Config config = new ConfigBuilder().withMasterUrl(masterURL)
                .withClientCertFile(certFile).withOauthToken(serviceAccountAccessToken).build();
</code></pre>

<p>Can I know how to get the serviceAccountAccessToken as described above using fabric8 java client ?</p>

<p>The client already does that for you.</p>

<p>If you just create an empty Config object:</p>

<pre><code>Config config = new ConfigBuilder().build();
</code></pre>

<p>or create the client, like:</p>

<pre><code>KubernetesClient client = new DefaultKubernetesClient();
</code></pre>

<p>from within a pod, it will automatically read the token for you.</p>

<p>If you need to pass it elsewhere, you can just:</p>

<pre><code>String token = config.getOauthToken();
</code></pre>

<p>or </p>

<pre><code>String token = client.getConfiguration().getOauthToken();
</code></pre>
