<p>I'm using k8s java client and need a way to get OAuth access token for some clusters. Now I can do that only with this bash script:</p>

<pre><code>export KUBECONFIG=~/.kube/&lt;config-file&gt;

APISERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
SECRET_NAME=$(kubectl get secrets | grep ^default | cut -f1 -d ' ')
TOKEN=$(kubectl describe secret $SECRET_NAME | grep -E '^token' | cut -f2 -d':' | tr -d " ")

echo "TOKEN: ${TOKEN}"
</code></pre>

<p>Is there a way to do that with java code? Don't ask for the whole solution but at least for some direction to look.</p>

Alexey  Usharovski
<p>Kubernetes is not involved in the OAuth side of things at all. That’s up to your IdP. More normally you would use a ServiceAccount token for automation though.</p>
