Created
June 23, 2019 08:09
-
-
Save shawnho1018/4ab92913231bd2d96bea2053456103a7 to your computer and use it in GitHub Desktop.
快速生成kubeconfig方法
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
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