Skip to content

Instantly share code, notes, and snippets.

@willnewby
Last active October 26, 2018 18:55
Show Gist options
  • Save willnewby/7a1866147e036c0cfbd26b05efba9d70 to your computer and use it in GitHub Desktop.
Save willnewby/7a1866147e036c0cfbd26b05efba9d70 to your computer and use it in GitHub Desktop.
Generate a .kube/config file from a ServiceAccount token
# 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