Created
July 22, 2022 19:48
-
-
Save Miladbr/6a151b7464916c17c9f62266a3c98572 to your computer and use it in GitHub Desktop.
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
clusterName=$1 | |
server=$2 | |
namespace=$3 | |
serviceAccount=$4 | |
set -o errexit | |
secretName=$(kubectl --namespace $namespace get serviceAccount $serviceAccount -o jsonpath='{.secrets[0].name}') | |
token=$(kubectl --namespace $namespace get secret/$secretName -o jsonpath='{.data.token}' | base64 --decode) | |
echo " | |
--- | |
apiVersion: v1 | |
kind: Config | |
clusters: | |
- name: ${clusterName} | |
cluster: | |
insecure-skip-tls-verify: true | |
server: ${server} | |
contexts: | |
- name: ${serviceAccount}@${clusterName} | |
context: | |
cluster: ${clusterName} | |
namespace: ${namespace} | |
user: ${serviceAccount} | |
users: | |
- name: ${serviceAccount} | |
user: | |
token: ${token} | |
current-context: ${serviceAccount}@${clusterName} | |
" > ${clusterName}.yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment