Last active
November 24, 2021 14:56
-
-
Save jwhb/233891f443e8b1bd066b4769ee96cea5 to your computer and use it in GitHub Desktop.
kubectl: extract serviceaccount token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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