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 등록 및 활용 가능
- 가이드 참고