Created
April 8, 2019 10:23
-
-
Save cbrgm/56866a8c82b0e205e5cadbf560e1c608 to your computer and use it in GitHub Desktop.
Create a kubeconfig for an existing serviceaccount in kubernetes
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/bash | |
# your server name goes here | |
server=https://my.k8s.cluster:6443 | |
# the name of the secret containing the service account token goes here | |
name=super-secret-token-2l269 | |
# the namespace containing the secret | |
namespace=kube-system | |
# don't touch this! | |
ca=$(kubectl get -n $namespace secret/$name -o jsonpath='{.data.ca\.crt}' | base64 --decode) | |
token=$(kubectl get -n $namespace secret/$name -o jsonpath='{.data.token}' | 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} | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment