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 목록이 보이면 성공