Skip to content

Instantly share code, notes, and snippets.

@Miladbr
Created July 22, 2022 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Miladbr/6a151b7464916c17c9f62266a3c98572 to your computer and use it in GitHub Desktop.
Save Miladbr/6a151b7464916c17c9f62266a3c98572 to your computer and use it in GitHub Desktop.
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