Skip to content

Instantly share code, notes, and snippets.

@jwhb
Last active November 24, 2021 14:56
Show Gist options
  • Save jwhb/233891f443e8b1bd066b4769ee96cea5 to your computer and use it in GitHub Desktop.
Save jwhb/233891f443e8b1bd066b4769ee96cea5 to your computer and use it in GitHub Desktop.
kubectl: extract serviceaccount token
#!/bin/sh
NAMESPACE=default
SERVICE_ACCOUNT=mysa
# kubectl -n $NAMESPACE create sa $SERVICE_ACCOUNT
kubectl -n $NAMESPACE get secret `kubectl -n $NAMESPACE get serviceaccount $SERVICE_ACCOUNT -ojsonpath="{.secrets[0].name}"` -ojsonpath="{.data.token}" | base64 -d
# BONUS: use kubectl with the service account token:
kubectl --token="${TOKEN}" -s https://api.<cluster-domain>:6443 --insecure-skip-tls-verify=true get pod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment