IaaS/퍼블릭클라우드

(GCP-GKE) VPC 기반 Private k8s 클러스터 만들기

armyost 2023. 11. 27. 22:53
728x90

지난 번에 구축한 VPC를 기반하여 GKE클러스터를 구축하려한다. 

https://armyost.tistory.com/446

 

GCP VPC 구축하기 (Public/Private Subnet 구축하기)

필자가 만들고자 하는 VPC는 다음과 같다. AWS에서는 Subnet이 Internet-gateway가 연결되어 있으면 Internet-facing되었다고 생각하고 public subnet이라고 단정짓는다. 하지만 GCP는 private-subnet에 대한 개념이

armyost.tistory.com

 

 

그리고 GKE 클러스터 노드들은 보안상 Private Network 구간에 배치토록 하겠다.

※ 관련링크 : https://cloud.google.com/kubernetes-engine/docs/how-to/private-clusters?hl=ko

 

비공개 클러스터 만들기  |  Google Kubernetes Engine(GKE)  |  Google Cloud

비공개 GKE 클러스터를 만드는 방법을 알아봅니다.

cloud.google.com

 


 

이제 GKE를 배포 해보자.

 

Cloud Shell에서 다음의 CLI를 실행한다.

$ gcloud container clusters create armyost-cluster \
    --location asia-northeast3 \ 
    --network armyost-vpc \
    --subnetwork=private-subnet \
    --enable-master-authorized-networks \
    --enable-ip-alias \
    --enable-private-nodes \
    --enable-private-endpoint \
    --cluster-ipv4-cidr=5.0.0.0/16 \
    --services-ipv4-cidr=5.1.0.0/16 \
    --master-ipv4-cidr=172.16.0.16/28 \
    --machine-type=e2-medium \ # Default e2-medium
    
## 한줄로 필요한 경우..
$ gcloud container clusters create armyost-cluster --location=asia-northeast3 --network=armyost-vpc --subnetwork=private-subnet --enable-master-authorized-networks --enable-ip-alias --enable-private-nodes --enable-private-endpoint --cluster-ipv4-cidr=5.0.0.0/16 --services-ipv4-cidr=5.1.0.0/16 --master-ipv4-cidr=172.16.0.16/28 --machine-type=e2-medium --num-nodes=1

## Public 에서 ControlPlain 에 접근이 필요할때, Private Endpoint 설정을 뺀다
$ gcloud container clusters create armyost-cluster --location=europe-west1 --network=armyost-vpc --subnetwork=private-subnet --enable-master-authorized-networks --enable-ip-alias --enable-private-nodes --cluster-ipv4-cidr=5.0.0.0/16 --services-ipv4-cidr=5.1.0.0/16 --master-ipv4-cidr=172.16.0.16/28 --machine-type=e2-medium --num-nodes=1

 

※ GKE Cluster CLI 옵션 설명https://cloud.google.com/sdk/gcloud/reference/container/clusters/create

 

gcloud container clusters create  |  Google Cloud CLI Documentation

 

cloud.google.com

 

 

만약 GKE 배포 중에 다음과 같은 오류가 발생할 때는 해당 리전에 대한 할당량을 상향시켜야 한다.

ERROR: (gcloud.container.clusters.create) ResponseError: code=403, message=Insufficient regional quota to satisfy request: resource "SSD_TOTAL_GB": request requires '900.0' and is short '400.0'. project has a quota of '500.0' with '500.0' available. View and manage quotas at https://console.cloud.google.com/iam-admin/quotas?usage=USED&project=armyost-prj.

 

아래와 같이 할당량을 기존 500GB에서 1TB로 상향하였다.

 

 

 

이제 CLI가 정상적으로 돌아가고, 원했던 데로 잘 설정이 되어 있다.

 

그리고 Worker Node 갯수, 네트워크 세팅 모두 정상적으로 완료되었다.


 

삭제시에는 다음 CLI를 실행시킨다.

$ gcloud container clusters delete -q armyost-cluster --location asia-northeast3

 


 

Container Cluster를 생성할때 --enable-private-endpoint로 Master Node Endpoint를 생성하면 Private Network의 Client를 --master-authorized-networks에 추가해야한다. 

 

만약 --enable-private-endpint 없이 public-endpoint로 노출될 수 있도록 세팅하였다면 Cloud Console에서도 kubectl이 접속되어 여러모로 편해진다. 다만 이는 보안을 고려하여 적용바란다. 

 

Cloud Console에서 kubectl 사용시 아래의 작업을 추가 진행한다.

 

$ dig +short myip.opendns.com @resolver1.opendns.com

 

$ gcloud container clusters update armyost-cluster \
--enable-master-authorized-networks \
--master-authorized-networks 확인된외부IP/32 \
--location=asia-northeast3

$ gcloud container clusters get-credentials armyost-cluster \
--project=armyost-prj \
--location=asia-northeast3

 

이제 kubectl get nodes를 해보자