If you want to use Bash Shell to call Kubernetes APIs, Here is the way to get the token and use it as follows:
Prepare variables
Prepare variables
#APISERVER="https://10.10.0.100:6443" $ APISERVER=$(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ") $ TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | \ grep -E '^token' | cut -f2 -d':' | tr -d '\t')Call APIs
$ curl $APISERVER/api --header "Authorization: Bearer ${TOKEN//[[:space:]]/}" --insecure { "kind": "APIVersions", "versions": [ "v1" ], "serverAddressByClientCIDRs": [ { "clientCIDR": "0.0.0.0/0", "serverAddress": "192.168.0.100:6443" } ] }