Skip to content

Instantly share code, notes, and snippets.

@warroyo
Created February 4, 2021 22:25
Show Gist options
  • Select an option

  • Save warroyo/7b748947dfcfbe661c21fe511f1e4db2 to your computer and use it in GitHub Desktop.

Select an option

Save warroyo/7b748947dfcfbe661c21fe511f1e4db2 to your computer and use it in GitHub Desktop.
getting a token from k8s service account
export APISERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
APISERVERNOHTTPS=$(echo $APISERVER | cut -c 9-)
FPRINT=$(openssl s_client -connect $APISERVERNOHTTPS < /dev/null 2>/dev/null | openssl x509 -fingerprint -sha256 -noout -in /dev/stdin)
export FINGERPRINT=$(echo $FPRINT | cut -c 20-)
TOKENNAME=$(kubectl -n kube-system get serviceaccount/dev-admin -o jsonpath='{.secrets[0].name}')
export TOKEN=$(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