Last active
July 13, 2019 14:54
-
-
Save peter-wangxu/c6907729309fb0e4c7899faac62b785e to your computer and use it in GitHub Desktop.
service-account-to-kubeconfig
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
# your server name goes here | |
server=https://<your apiserver address>:6443 | |
# the name of the secret containing the service account token goes here | |
name=crd-reader-sa-token-rz5xp | |
# namespace to use, set NAMESPACE_OVERRIDE to use other namespace | |
namespace=${NAMESPACE_OVERRIDE:=default} | |
ca=$(kubectl get secret/$name -o jsonpath='{.data.ca\.crt}' -n $namespace) | |
token=$(kubectl get secret/$name -o jsonpath='{.data.token}' -n $namespace | base64 --decode) | |
namespace=$(kubectl get secret/$name -o jsonpath='{.data.namespace}' -n $namespace | base64 --decode) | |
echo " | |
apiVersion: v1 | |
kind: Config | |
clusters: | |
- name: default-cluster | |
cluster: | |
certificate-authority-data: ${ca} | |
server: ${server} | |
contexts: | |
- name: default-context | |
context: | |
cluster: default-cluster | |
namespace: default | |
user: default-user | |
current-context: default-context | |
users: | |
- name: default-user | |
user: | |
token: ${token} | |
" > sa.kubeconfig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment