Difference between revisions of "Access Kubernetes REST API using default token"

From wikieduonline
Jump to navigation Jump to search
Line 2: Line 2:
 
  TOKEN=$([[kubectl describe secret default-token]] | grep -E '^token' | cut -f2 -d':' | tr -d " ")
 
  TOKEN=$([[kubectl describe secret default-token]] | grep -E '^token' | cut -f2 -d':' | tr -d " ")
 
   
 
   
  [[curl]] $APISERVER[[/api]] [[--header]] "[[Authorization: Bearer]] $TOKEN" --insecure
+
  [[curl]] $APISERVER[[/api]] [[--header]] "[[Authorization: Bearer]] $TOKEN" --insecure <ref> https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/</ref>
Ref: https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/
 
  
 
== Examples ==
 
== Examples ==

Revision as of 17:11, 24 October 2023

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

curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure [1]

Examples

{"type":"error","status":"401","message":"Unauthorized 401: must authenticate"}
{
 "kind": "APIVersions",
 "versions": [
   "v1"
 ],
 "serverAddressByClientCIDRs": [
   {
     "clientCIDR": "0.0.0.0/0",
     "serverAddress": "ip-172-16-37-214.ec2.internal:443"
   }
 ]
}%


Errors

Error from server (NotFound): secrets "default-token" not found

Related

See also

  • https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/
  • Advertising: