How to connect GKE Cluster with kubeconfig - cloud-barista/cb-spider GitHub Wiki

โ€ป ํŠน์ด์‚ฌํ•ญ

  • 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

[OpenLens ์—ฐ๋™ ๋ฐฉ๋ฒ•]

๊ด€๋ฆฌ์ž ๊ถŒํ•œ์œผ๋กœ powerShell ์‹คํ–‰

  • ์ดํ•˜ powershell ๋‚ด๋ถ€ ์‹คํ–‰

1. gloud ์„ค์น˜

  • $ Install-Module GoogleCloud

2. gcloud cli ์ธ์ฆ

  • credentials ํŒŒ์ผ ์ค€๋น„(from GCP)
    • ์˜ˆ์‹œ
    {
      "type": "service_account",
      "project_id": "powerkimhub",
      "private_key_id": "51b5e68a1a9988c1eb6f4c235917921ad9ada913",
      "private_key": "-----BEGIN PRIVATE KEY-----\... ์ค‘๋žต -----END PRIVATE KEY-----\n",
      "client_email": "[email protected]",
      "client_id": "1072544778xxxxxxxxxxxxx",
      "auth_uri": "https://accounts.google.com/o/oauth2/auth",
      "token_uri": "https://oauth2.googleapis.com/token",
      "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
      "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/powerkimhub%40powerkimhub.iam.gserviceaccount.com"
    }
    
  • ์ธ์ฆ ์ ์šฉ
    $ gcloud auth login --cred-file=./credentials
    

3. gcloud auth plugin ์„ค์น˜

  • $ gcloud components install gke-gcloud-auth-plugin
    • (์‹œ๊ฐ„์ด ์ข€ ๊ฑธ๋ฆผ, waiting ์ƒํƒœ์—์„œ enter๋‚˜ space ์ž…๋ ฅ์ด ํ•„์š”ํ•  ์ˆ˜๋„ ์žˆ์Œ)

4. application-default-credentials ์ถ”๊ฐ€

  • gcloud auth application-default login (gcp ๊ณ„์ • ๊ณ„์ •์œผ๋กœ)
  • (์‹œ๊ฐ„์ด ์ข€ ๊ฑธ๋ฆผ, waiting ์ƒํƒœ์—์„œ enter๋‚˜ space ์ž…๋ ฅ์ด ํ•„์š”ํ•  ์ˆ˜๋„ ์žˆ์Œ)
  • ์‹คํ–‰ ํ›„ ์ •๋ณด ์ €์žฅ ์œ„์น˜: C:\Users\power\AppData\Roaming\gcloud\application_default_credentials.json

5. kubectl ์„ค์น˜

  • gcloud components install kubectl

6. OpenLens ์„ค์น˜

7. CB-Spider PMKS API๋กœ๋ถ€ํ„ฐ Kubeconfig ํš๋“

  • ๋˜๋Š” gcloud cli ํ™œ์šฉ
    • ์˜ˆ์‹œ: gcloud container clusters get-credentials cluster-1 --project powerkimhub --zone us-central1-c

8. OpenLens์— ๋Œ€์ƒ Cluster ๋“ฑ๋ก

  • ํš๋“ํ•œ Kubeconfig๋ฅผ OpenLens์— ์ถ”๊ฐ€
  • ๋Œ€์ƒ Cluster์— ์—ฐ๋™ ๋ฐ ์ œ์–ด ๊ฐ€๋Šฅ

9. ์—ฐ๋™ ๋ฐ ์ œ์–ด ์‹œํ—˜

  • (1) Kubeconfig ๋“ฑ๋ก
    • ๋‹ค์Œ ํ™”๋ฉด์—์„œ ์ขŒ์ธก์—์„œ ์šฐ์ธก ์ˆœ์„œ๋กœ red underbar ์‹คํ–‰
      • image
  • (2) ๋“ฑ๋ก๋œ Cluster ๋ชฉ๋ก์—์„œ Connect ์‹คํ–‰
  • (3) kube prometheus ์„ค์น˜(์„ค์น˜์‹œ node ์ •๋ณด ํ™•์ธ ๊ฐ€๋Šฅ)
    • ์‹คํ–‰ ๋ฉ”๋‰ด: Helm -> Charts : kube-prometheus ์„ค์น˜
  • (4) nginx Service ๋ฐฐํฌ (LB Service Type ์‹œํ—˜์šฉ)
    • ์‹คํ–‰ ๋ฉ”๋‰ด: Helm -> Charts : nginx ์„ค์น˜
  • (5) LB ํ†ตํ•œ nginx ์ ‘์† ํ™•์ธ
    • ์‹คํ–‰ ๋ฉ”๋‰ด: Network -> Services: nginx-xxx
    • External IP ํ™•์ธ ๋ฐ ๋ธŒ๋ผ์šฐ์ € ์˜คํ”ˆ
    • ์„ฑ๊ณต์‹œ ๋‹ค์Œ ํ™”๋ฉด ๋กœ๋”ฉ
      • image

[kubectl ์—ฐ๋™ ๋ฐฉ๋ฒ•]

1. ์œ„ [OpenLens ์—ฐ๋™ ๋ฐฉ๋ฒ•] ์ฐธ๊ณ ํ•˜์—ฌ kubectl ์„ค์น˜

2. ~/.kube/config์— Kubeconfig ๋‚ด์šฉ ๋ณต์‚ฌ

3. ์—ฐ๋™ ์‹œํ—˜

  • $ kubectl get pods --all-namespaces
  • Pod ๋ชฉ๋ก์ด ๋ณด์ด๋ฉด ์„ฑ๊ณต