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์™€๋Š” ๋‹ค๋ฆ„

3. 1+2์œผ๋กœ Kubeconfig ์ƒ์„ฑ

  • Kubeconfig Template ๋ฌธ์ž์—ด์—์„œ ๋‹ค์Œ ๊ฐ’๋“ค์„ 2.์—์„œ ๊ตฌํ•œ ๊ฐ’์œผ๋กœ ๊ต์ฒดํ•˜์—ฌ ์ƒ์„ฑํ•จ
    • ##CLUSTERNAME##
    • ##ENDPOINT##
    • ##CA-CERT##

4. Kubeconfig ์ด์šฉํ•œ Cluster ์—ฐ๋™

  • kubectl ๋ฐ OpenLens ๋“ฑ์˜ ๋„๊ตฌ์— Kubeconfig ๋“ฑ๋ก ๋ฐ ํ™œ์šฉ ๊ฐ€๋Šฅ
  • ๊ฐ€์ด๋“œ ์ฐธ๊ณ