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 ์คํ
- ๋ค์ ํ๋ฉด์์ ์ข์ธก์์ ์ฐ์ธก ์์๋ก red underbar ์คํ
- (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 ํ์ธ ๋ฐ ๋ธ๋ผ์ฐ์ ์คํ
- ์ฑ๊ณต์ ๋ค์ ํ๋ฉด ๋ก๋ฉ
[kubectl ์ฐ๋ ๋ฐฉ๋ฒ]
1. ์ [OpenLens ์ฐ๋ ๋ฐฉ๋ฒ] ์ฐธ๊ณ ํ์ฌ kubectl ์ค์น
2. ~/.kube/config์ Kubeconfig ๋ด์ฉ ๋ณต์ฌ
3. ์ฐ๋ ์ํ
$ kubectl get pods --all-namespaces
- Pod ๋ชฉ๋ก์ด ๋ณด์ด๋ฉด ์ฑ๊ณต