Created
April 7, 2022 15:54
-
-
Save mdrakiburrahman/ce791ec4afcef7ce18f59f9a50bdb7fe to your computer and use it in GitHub Desktop.
Create Kubeconfig from Service Account
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
# the Namespace and ServiceAccount name that is used for the config | |
namespace=arc | |
serviceAccount=arcOnboard | |
###################### | |
# actual script starts | |
set -o errexit | |
secretName=$(kubectl --namespace $namespace get serviceAccount $serviceAccount -o jsonpath='{.secrets[0].name}') | |
ca=$(kubectl --namespace $namespace get secret/$secretName -o jsonpath='{.data.ca\.crt}') | |
token=$(kubectl --namespace $namespace get secret/$secretName -o jsonpath='{.data.token}' | base64 --decode) | |
echo " | |
--- | |
apiVersion: v1 | |
kind: Config | |
clusters: | |
- name: ${clusterName} | |
cluster: | |
certificate-authority-data: ${ca} | |
server: ${server} | |
contexts: | |
- name: ${serviceAccount}@${clusterName} | |
context: | |
cluster: ${clusterName} | |
namespace: ${namespace} | |
user: ${serviceAccount} | |
users: | |
- name: ${serviceAccount} | |
user: | |
token: ${token} | |
current-context: ${serviceAccount}@${clusterName} | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment