Friday, September 30, 2022

Kubernetes Dashboard Secret

The short gist

 Running the Windows Command Prompt, load the local proxy:

kubectl proxy

Then execute cURL like so:

curl -H "Content-Type: application/json" -d "{}" http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/serviceaccounts/admin-user/token

The TokenResponse JSON object should appear in the reply that ends with

"status": {

"token": "eyJhb...",

"expirationTimestamp": "2022-09-30T10:01:13Z"

}

The long story

There used to be a time when the Kubernetes Dashboard came out of the box with a command for retrieving the default token using the command line. Until it didn't.

Scouring many forums and discussion threads, it seems to have been removed.

Secret token not generating - General Discussions - Discuss Kubernetes

Not able to login to Kubernetes dashboard using token with service account - Stack Overflow

Even the official documentation was nary a help.

dashboard/creating-sample-user.md at master · kubernetes/dashboard · GitHub

dashboard/README.md at master · kubernetes/dashboard · GitHub

Some people suggested overriding with the --enable-skip-login flag, which didn't work for me either.

Running Kubernetes and the dashboard with Docker Desktop (andrewlock.net)

The trail eventually lead me to the suggestion of calling the K8s API to get what I want.

TokenRequest | Kubernetes

Which in turn allowed me to locate this post that gave some useful headway.

A Look at How to Use TokenRequest Api | jpweber blog

This has troubled me for over a month as I had to repeatedly get interrupted with other tasks. I'm at least satisfied that this has arrived at a conclusion before the weekend.