Reputation: 1442
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:
export KUBECONFIG=~/.kube/<config-file>
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}"
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.
Upvotes: 0
Views: 641
Reputation: 11613
The Kubernetes config is stored as a YAML file. Use a library to read and parse it, example
In the end you'll get an object with all the keys and values from the config. Just access directly what you need.
Upvotes: 0
Reputation: 54249
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.
Upvotes: 2