Skip to content

How to create GKE Kubeconfig

ByoungSeob Kim edited this page Jan 3, 2023 · 7 revisions

[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를 이용한 필요한 값 획득

3. 1+2으로 Kubeconfig 생성

  • Kubeconfig Template 문자열에서 다음 값들을 2.에서 구한 값으로 교체하여 생성함
    • ##CLUSTERNAME##
    • ##ENDPOINT##
    • ##CA-CERT##

4. Kubeconfig 이용한 Cluster 연동

Table of contents



Clone this wiki locally