Skip to content

Instantly share code, notes, and snippets.

@kenazk
Last active August 21, 2019 15:40
Show Gist options
  • Save kenazk/cfce793d7ec29b876acaf3d629c3345c to your computer and use it in GitHub Desktop.
Save kenazk/cfce793d7ec29b876acaf3d629c3345c to your computer and use it in GitHub Desktop.
Getting Kubernetes Service Account Token

Retrieving a Kubernetes Service Account Token

Prerequisites: Kubernetes cluster and local kubectl configuration

  1. Look for which service account you want to use
$ kubectl -n kube-system get serviceaccount
  1. Retrieve the token name
$ TOKENNAME=`kubectl -n kube-system get serviceaccount/[INSERT SERVICE ACCOUNT NAME] -o jsonpath='{.secrets[0].name}'`
  1. Retrieve the base64 encoded token value.
$ kubectl -n kube-system get secret $TOKENNAME -o jsonpath='{.data.token}' | base64 --decode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment