Skip to content

Instantly share code, notes, and snippets.

@shawnho1018
Created June 23, 2019 08:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnho1018/4ab92913231bd2d96bea2053456103a7 to your computer and use it in GitHub Desktop.
Save shawnho1018/4ab92913231bd2d96bea2053456103a7 to your computer and use it in GitHub Desktop.
快速生成kubeconfig方法
context=$1 #後端K8S Cluster的名稱
kubectl apply -f ./sa-admin.yaml # 執行
name=$(kubectl describe sa gimbal-sa --context=$context | grep Tokens | awk '{print $2}')
ca=$(kubectl get secret/$name -o jsonpath='{.data.ca\.crt}' --context=$context)
token=$(kubectl get secret/$name -o jsonpath='{.data.token}' --context=$context | base64 --decode)
namespace=$(kubectl get secret/$name -o jsonpath='{.data.namespace}' --context=$context | base64 --decode)
echo "
apiVersion: v1
kind: Config
clusters:
- name: $context
cluster:
certificate-authority-data: ${ca}
server: ${server}
contexts:
- name: $context
context:
cluster: $context
namespace: default
user: default-user
current-context: $context #Discoverer會依據current-context所指定的context來發現後端Cluster內的服務。
users:
- name: default-user
user:
token: ${token}
" > "${context}-kube-config"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment