How to create GKE Kubeconfig - cloud-barista/cb-spider GitHub Wiki
[GKE Cluster Kubeconfig ์์ฑ ๊ฐ์ด๋ ๊ฐ์]
- kubectl ๋ฐ Lens ๋ฑ์ ๋๊ตฌ์์ Kubernetes Cluster ์ ์/ํ์ฉ์ ์ํด์ Kubeconfig(./kube/config)๊ฐ ํ์ํจ
- CB-Spider/PMKS API๋ Kubeconfig๋ฅผ ์ ๊ณตํจ
- GCP GKE SDK API๋ Kubeconfig๋ฅผ ์ ๊ณตํ์ง ์์
- GCP Driver ๋ด๋ถ์์ Kubeconfig๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ด ์๋์ ๊ฐ์
โป ํน์ด์ฌํญ
- GKE ๊ฒฝ์ฐ kubectl์ด๋ Lens ๋๊ตฌ๋ฅผ ์ด์ฉํ์ฌ Cluster ์ ์/ํ์ฉ ์์๋
- ๋๊ตฌ ์์น์ gcloud cli ์ค์น ๋ฐ ๋์ Cluster ์ธ์ฆ ์ ์ฐจ๊ฐ ํ์ํ๋ฉฐ,
- kubectl ๋ฐ Lens์ gcloud cli์ ์ํธ์์ฉ์ผ๋ก ์คํ๋จ
- GKE ๊ฒฝ์ฐ ์ด๋ฏธ ์ค์น ๋ฐ ์ธ์ฆ๋ gcloud cli๋ฅผ ์ด์ฉํ์ฌ Kubeconfig๋ฅผ ํ๋ ํ ์๋ ์์
- ์์:
gcloud container clusters get-credentials cluster-1 --project powerkimhub --zone us-central1-c
- ์์:
[์์ฑ ์์ฝ]
1. Kubeconfig template ์ ์
2. GKE API๋ฅผ ์ด์ฉํ ํ์ํ ๊ฐ ํ๋
3. `1+2`์ผ๋ก `Kubeconfig` ์์ฑ
4. Kubeconfig ์ด์ฉํ Cluster ์ฐ๋
1. Kubeconfig template ์ ์
-
๋ค์ link์
5.Create a kubeconfig.yaml file containing the following
๋ถ๋ถ ์ฐธ๊ณ -
Kubeconfig Template ์์
apiVersion: v1 kind: Config clusters: - name: ##CLUSTERNAME## cluster: server: https://##ENDPOINT## certificate-authority-data: ##CA-CERT## users: - name: cb-spider user: exec: apiVersion: client.authentication.k8s.io/v1beta1 args: - --use_application_default_credentials command: gke-gcloud-auth-plugin installHint: Install gke-gcloud-auth-plugin for kubectl by following https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl#install_plugin provideClusterInfo: true contexts: - context: cluster: ##CLUSTERNAME## user: cb-spider name: ##CLUSTERNAME## current-context: ##CLUSTERNAME##
-
โป ํน์ด์ฌํญ: K8S ๋ฒ์ ๋ฐ ํฅํ GKE ๊ท๊ฒฉ ๋ณ๊ฒฝ์ ์์กด์ ์ผ ์ ์์
- ์ํ K8S ๋ฒ์ : 1.24.7-gke.900
2. GKE API๋ฅผ ์ด์ฉํ ํ์ํ ๊ฐ ํ๋
- Kubeconfig ์์ฑ์ ์ํด์๋ ๋ค์ 2๊ฐ์ง ๊ฐ์ด ํ์ํจ
- (1) ClusterName
- (2) Endpoint
- (3) ClusterCaCertificate
- ๋ค์ API docs๋ฅผ ์ฐธ๊ณ ํ์ฌ
Cluster
(Cluster Info Object) ๊ฐ์ฒด ํ๋ ํ ๋ค์ ์์น์์ 2๊ฐ์ง ๊ฐ ํ๋์ด ๊ฐ๋ฅํจ- (1) ClusterName:
Cluster.Name
- (2) Endpoint:
Cluster.Endpoint
- (3) ClusterCaCertificate:
Cluster.MasterAuth.ClusterCaCertificate
- โป gcloud cli๋ก ๊ตฌํ๋ ๋ฐฉ๋ฒ:
gcloud container clusters describe cluster-1 --format="value(masterAuth.clusterCaCertificate)" --project powerkimhub --zone=us-central1-c
- โป GCP Web Console์์ ์ ๊ณตํ๋
Cluster Certificate
์๋ ๋ค๋ฆ
- โป gcloud cli๋ก ๊ตฌํ๋ ๋ฐฉ๋ฒ:
- (1) ClusterName:
1+2
์ผ๋ก Kubeconfig
์์ฑ
3. - Kubeconfig Template ๋ฌธ์์ด์์ ๋ค์ ๊ฐ๋ค์ 2.์์ ๊ตฌํ ๊ฐ์ผ๋ก ๊ต์ฒดํ์ฌ ์์ฑํจ
##CLUSTERNAME##
##ENDPOINT##
##CA-CERT##
4. Kubeconfig ์ด์ฉํ Cluster ์ฐ๋
- kubectl ๋ฐ OpenLens ๋ฑ์ ๋๊ตฌ์ Kubeconfig ๋ฑ๋ก ๋ฐ ํ์ฉ ๊ฐ๋ฅ
- ๊ฐ์ด๋ ์ฐธ๊ณ