Created
March 17, 2020 04:16
-
-
Save abhisek/2a30589864564f487bee47aa76162968 to your computer and use it in GitHub Desktop.
Generate kubeconfig for Service Account
This file contains hidden or 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 | |
export TARGET_CONFIGSERVER=$(kubectl cluster-info | grep master | awk '{print $NF}' | sed 's/\x1B\[[0-9;]\+[A-Za-z]//g') | |
export TARGET_TOKENNAME=$(kubectl -n developers get sa developer-sa -o jsonpath='{.secrets[0].name}') | |
export TARGET_CONFIGTOKEN=$(kubectl -n developers get secret $TARGET_TOKENNAME -o "jsonpath={.data.token}" | base64 -d) | |
export TARGET_CONFIGCRT=$(kubectl -n developers get secret $TARGET_TOKENNAME -o "jsonpath={.data['ca\.crt']}") | |
cat <<EOF | |
apiVersion: v1 | |
kind: Config | |
users: | |
- name: default | |
user: | |
token: $TARGET_CONFIGTOKEN | |
clusters: | |
- cluster: | |
certificate-authority-data: $TARGET_CONFIGCRT | |
server: $TARGET_CONFIGSERVER | |
name: $TARGET_CLUSTERNAME | |
contexts: | |
- context: | |
cluster: $TARGET_CLUSTERNAME | |
user: default | |
name: research | |
current-context: research | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment