Last active
October 26, 2018 18:55
-
-
Save willnewby/7a1866147e036c0cfbd26b05efba9d70 to your computer and use it in GitHub Desktop.
Generate a .kube/config file from a 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
# your server name goes here | |
server=https://localhost:8080 | |
# the name of the secret containing the service account token goes here | |
name=serviceaccount-yay | |
ca=$(kubectl get secret/$name -o jsonpath='{.data.ca\.crt}') | |
token=$(kubectl get secret/$name -o jsonpath='{.data.token}' | base64 -D) | |
namespace=$(kubectl get secret/$name -o jsonpath='{.data.namespace}' | base64 -D) | |
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: ${namespace} | |
user: default-user | |
current-context: default-context | |
users: | |
- name: default-user | |
user: | |
token: ${token} | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment