๋ชฉํ
๊ธฐ์กด์ ์กด์ฌํ๋ Monolithic ์น์ฌ์ดํธ๋ฅผ ๋ง์ดํฌ๋ก์๋น์ค๋ก ๋ถ๋ฆฌํ๊ณ , ์ด ์น์ฌ์ดํธ๋ฅผ ์ปจํ ์ด๋ํ ํด์ GKE ํ๊ฒฝ์ ๋ฐฐํฌํ๋ค.
๋จผ์ ๋ ๊ธฐ์กด monolith ์น์ฌ์ดํธ๋ฅผ build, deployํด์ ์ ๋๋ก ์๋ํ๋์ง ํ ์คํธํด๋ณด๊ณ , ๊ฐ ์๋น์ค๋ฅผ ๋ง์ดํฌ๋ก์๋น์ค๋ก ์ชผ๊ฐ์ ์ต์ข ๋ฐฐํฌํ๋ค.
Task 1. Download the monolith code and build your container
Cloud Shell์์, ์ฃผ์ด์ง git repo๋ฅผ ๋ค์ด๋ก๋๋ฐ๊ณ , ๋ฃจํธ ๋๋ ํ ๋ฆฌ์ ์๋ setup.sh ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๋ค.
์ด setup.sh ์คํฌ๋ฆฝํธ์๋ ํ๋ก์ ํธ์ ํ์ํ dependencies๋ฅผ ์ค์นํด์ฃผ๋ shell๋ช ๋ น์ด๊ฐ ์๋ค.
๊ทธ๋ฆฌ๊ณ ๋์ Cloud Shell์ด ์ต์ ๋ฒ์ ์ NodeJS๋ฅผ ์คํํ๋๋ก ํ๋ค.
nvm install --lts
monolith ํ๋ก์ ํธ ๋น๋ ๊ฒฐ๊ณผ๋ฌผ์ Artifact Registry๋ก ํธ์ฌํ๋ค.
์ฐ์ถ๋ฌผ์ ์๋์ ๊ฐ๋ค.
- Repo: gcr.io/${GOOGLE_CLOUD_PROJECT}
- Image name: Monolith Identifier
- Image version: 1.0.0
๋จผ์ Cloud Build API ๋ฅผ ํ์ฑํํ๊ธฐ ์ํด ์๋ ์ปค๋งจ๋๋ฅผ ์ ๋ ฅํ๋ค.
gcloud services enable cloudbuild.googleapis.com
์๋ monolith ํด๋น ํด๋ ์์น๋ก ์ด๋ ํ,
cd ~/monolith-to-microservices/monolith
Cloud Build๋ฅผ ์คํํด ์์ค์ฝ๋๋ฅผ ๋น๋์ํค๊ณ , Artifact Registry๋ก ํธ์ฌํ๋ค.
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/{Monolith Identifier}:1.0.0 .
์๋๋ผ๋ฉด docker container ๋น๋ํ๊ณ , ์ด๋ฏธ์ง๋ฅผ ๋ณด๊ดํ๋ registry์ ํธ์ฌํ๋ ๊ฑธ 2๋จ๊ณ์ ๊ฑธ์ณ์ ํด์ผํ์ง๋ง, Cloud Build ๋ `gcloud builds submit` ๋ช ๋ น์ด ํ ์ค๋ก ์ด 2๋จ๊ณ๋ฅผ ๋ชจ๋ ์คํํ๋ค.
Google Cloud Build๊ฐ ๋๋ ํ ๋ฆฌ์ ํ์ผ๋ค์ ์์ถํด์ Google Cloud Storage Bucket์ผ๋ก ์ฎ๊ธฐ๋๋ฐ, ์ด ๋น๋ ํ๋ก์ธ์ค๋ ๋ฒํท์ ์๋ ๋ชจ๋ ํ์ผ์ ๊ฐ์ ธ์ค๊ณ Dockerfile์ ์ฌ์ฉํ์ฌ Docker build ํ๋ก์ธ์ค๋ฅผ ์คํํ๋ค.
`--tag` ํ๋๊ทธ๋ก ๋์ปค์ด๋ฏธ์ง ํธ์คํธ๋ฅผ gcr.io๋ก (google container registry์ ์ฝ์. ๊ตฌ๊ธํด๋ผ์ฐ๋์์ ๋์ปค ์ปจํ ์ด๋ ์ด๋ฏธ์ง๋ฅผ ๊ด๋ฆฌ/์ ์ฅํ๋ Artifact Registry์ ์ด์ ๋ฒ์ ์๋น์ค) ์ง์ ํ์์ผ๋ฏ๋ก Artifact Registry๋ก ๋์ปค์ด๋ฏธ์ง๊ฐ ์ฌ๋ผ๊ฐ๋ค.
Task 2. Create a kubernetes cluster and deploy the application
์ด์ ์ด๋ฏธ์ง๊ฐ Artifact Registry์ ์ ์ฅ๋์ด์์ผ๋ฏ๋ก ์น์ฌ์ดํธ ๋ฐฐํฌ๋ฅผ ์ํ Kubernetes cluster๋ฅผ ์์ฑํ๋ค.
ํด๋ฌ์คํฐ๋ ์๋์๊ฐ์ด ์์ฑ๋์ด์ผํ๋ค.
- Cluster name: Cluster Name
- Region: REGION
- Node count: 3
๋จผ์ Google Kubernetes Engine์ ์ฌ์ฉํ ์ ์๊ฒ Containers API๋ฅผ ํ์ฑํ ์ํจ๋ค.
gcloud services enable container.googleapis.com
REGION์ ์ค์ ํ๋ค.
gcloud config set compute/zone {REGION}
GKE ํด๋ฌ์คํฐ๋ฅผ 3๊ฐ ์์ฑํ๋ค.
gcloud container clusters create {ClusterName} --num-nodes 3
์๋ ๋ช ๋ น์ด๋ก ์์ฑ๋ ํด๋ฌ์คํฐ VM ์ธ์คํด์ค 3๊ฐ๋ฅผ ํ์ธ๊ฐ๋ฅํ๋ค.
gcloud compute instances list
๋น๋๋ ์ด๋ฏธ์ง๋ ์๊ณ , ํด๋ฌ์คํฐ๋ ์คํ๋๊ณ ์๊ณ , ์ด์ ์น์ฑ์ ๋ฐฐํฌํ ์ ์๋ค.
๋น๋ํ ์ด๋ฏธ์ง๋ฅผ ํด๋ฌ์คํฐ์ ๋ฐฐํฌํด์ผ๋๋ค. ํ์ง๋ง ๋ฐฐํฌ๋งํ๋ฉด ์ธ๋ถ์์๋ ์ ๊ทผ์ด ๋ถ๊ฐํ๋ฏ๋ก ๋ฌธ์ ์์ ์ฃผ์ด์ง๋๋ก 8080ํฌํธ์์ ์๋์ค์ธ ์ฑ์ 80ํฌํธ๋ก ๋ ธ์ถ์ํจ๋ค.
- Cluster name: Cluster Name
- Container name: Monolith Identifier
- Container version: 1.0.0
- Application port: 8080
- Externally accessible port: 80
GKE cluster์ ์ฑ์ ๋ฐฐํฌํ๊ณ ๊ด๋ฆฌํ๊ธฐ ์ํด์๋ `kubectl`CLI๋ฅผ ํตํด Kubernetes cluster management system๊ณผ ์ํตํด์ผํ๋ค.
์ฌ๊ธฐ์๋ ์ฑ์ ๋ฐฐํฌํ๊ธฐ ์ํด ์๋์ ๊ฐ์ด `kubectl create deployment` command๋ฅผ ์ฌ์ฉํ๋ค.
kubectl create deployment {Monolith Identifier} --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/{Monolith Identifier}:1.0.0
์ฑ์ด ์ ๋ฐฐํฌ๋์ด์๋์ง ํ์ธํ๋ค.
kubectl get all
NAME READY STATUS RESTARTS AGE
pod/monolith-7d8bc7bf68-htm7z 1/1 Running 0 6m21s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.27.240.1 <none> 443/TCP 24h
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.apps/monolith 1 1 1 1 20m
NAME DESIRED CURRENT READY AGE
replicaset.apps/monolith-7d8bc7bf68 1 1 1 20m
</none>
์ฟ ๋ฒ๋คํฐ์ค๋ ์ฑ๋ค์ Pods๋ผ๊ณ ํํํ๋๋ฐ, ์ปจํ ์ด๋ ๋จ์๋ฅผ ๋ํ๋ธ๋ค. Pod๋ ์ฟ ๋ฒ๋คํฐ์ค์์ ๊ฐ์ฅ ์์ ๋ฐฐํฌ๋จ์์ด๋ค.
์ด์ GKE์ ๋ฐฐํฌ๋ ์๋ฃ๋์์ผ๋, ํด๋ฌ์คํฐ ์ธ๋ถ์์ ์ ๊ทผํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์ผ๋ฏ๋ก ๋ช ์์ ์ผ๋ก ๋ ธ์ถ์์ผ์ฃผ์ด์ผํ๋ค.
์ธํฐ๋ท์์ ์น์ฌ์ดํธ๋ฅผ ๋ ธ์ถ์ํค๊ธฐ์ํด ์๋ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ๋ค.
kubectl expose deployment {Monolith Identifier} --type=LoadBalancer --port 80 --target-port 8080
GKE๊ฐ ์ด๋ค ์ธ๋ถ IP๋ฅผ ํ ๋นํ๋์ง ๋ณด๋ ค๋ฉด ์ฟ ๋ฒ๋คํฐ์ค service ๋ช ๋ น์ด๋ฅผ ํตํด ์ ์ ์๋ค.
kubectl get service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
monolith 10.3.251.122 203.0.113.0 80:30877/TCP 3d
์์๊ฐ์ Output์ด ๋์ค๊ณ , External-IP๋ฅผ ๋ณต์ฌํด ์ธํฐ๋ท ๋ธ๋ผ์ฐ์ ์ฐฝ์ "http://203.0.113.0" ๋ผ๊ณ ์น๋ฉด, ๋ฐฐํฌ๋ ์น์ฑ์ ์ธํฐ๋ท์์ ์ ๊ทผ๊ฐ๋ฅํ๋ค.

์ด์ ๊ธฐ์กด ๋ชจ๋ ธ๋ฆฌ์ค ์น์ฌ์ดํธ๊ฐ GKE ์์์ ์ ์๋ํ๋ ๊ฒ์ ํ์ธํ์์ผ๋ฏ๋ก, ๊ฐ ์๋น์ค๋ฅผ ๋ง์ดํฌ๋ก์๋น์ค๋ก ์ชผ๊ฐ์ผํ๋ค. Lab์์๋ ์ด๋ฏธ Orders, Products, and Frontend ์๋น์ค ๋จ์๋ก ๋ถ๋ฆฌํ๋ค.
Task 3. Create new microservices
์๋ ์๋น์ค๋ฅผ ์ปจํ ์ด๋ํ์ํจ๋ค.
| Orders Microservice | Service root folder: ~/monolith-to-microservices/microservices/src/orders GCR Repo: gcr.io/${GOOGLE_CLOUD_PROJECT} Image name: Orders Identifier Image version: 1.0.0 |
| Products Microservice | Service root folder: ~/monolith-to-microservices/microservices/src/products GCR Repo: gcr.io/${GOOGLE_CLOUD_PROJECT} Image name: Products Identifier Image version: 1.0.0 |
๋จผ์ ์ฝ๋๋ฒ ์ด์ค๊ฐ ์ ๊ณต๋์ด์๋ ๊ฐ ์์ค์ฝ๋์ ๋ฃจํธ๋ก ์ด๋ํ์ฌ, Cloud Build๋ก ๋์ปค ์ปจํ ์ด๋๋ฅผ ์์ฑํ๋ค.
๋์์ ์๋ --tag ์ต์ ๋ช ๋ น์ด๋ก, ๋์ปค ์ด๋ฏธ์ง๋ฅผ Artifact Registry์ ํธ์ฌํ๋ค.
cd ~/monolith-to-microservices/microservices/src/order
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/{Orders Identifier}:1.0.0 .
cd ~/monolith-to-microservices/microservices/src/product
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/{Products Identifier}:1.0.0 .
Task 4. Deploy the new microservices
Monolith์์ ๋ฐฐํฌํ๋๊ฒ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก, ๋ง์ดํฌ๋ก์๋น์ค๋ฅผ ์ํด ์๋ก๋ง๋ ์ปจํ ์ด๋๋ค๋ ๊ฐ์ ํ๋ก์ธ์ค๋ก ๋ฐฐํฌํ๋ค.
| Orders Microservice | Cluster name: Cluster Name Container name: Orders Identifier Container version: 1.0.0 Application port: 8081 Externally accessible port: 80 |
| Products Microservice | Cluster name: Cluster Name Container name: Products Identifier Container version: 1.0.0 Application port: 8082 Externally accessible port: 80 |
orders, products ์๋น์ค๋ฅผ ๊ฐ๊ฐ ๋ฐฐํฌํ๊ณ , ๋ฐฐํฌ๋ ์ฑ์ ๋ฌธ์ ์ ๋ช ์๋์ด์๋ ํฌํธ๋ก ๋งคํ์ํจ๋ค.
kubectl create deployment {Orders Identifier} --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/{Orders Identifier}:1.0.0โจ
kubectl expose deployment {Orders Identifier} --type=LoadBalancer --port 80 --target-port 8081
kubectl create deployment {Products Identifier} --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/{Products Identifier}:1.0.0โจ
kubectl expose deployment {Products Identifier} --type=LoadBalancer --port 80 --target-port 8082
์๋ ์๋น์ค ๋ช ๋ น์ด๋ก ๊ฐ external IP๋ฅผ ํ์ธํ๋ค.
kubectl get service
IP ์ฃผ์๋ก ์๋ ์ฃผ์๋ก ๋ค์ด๊ฐ๋ฉด, ๋ฐฐํฌ๊ฐ ์ฑ๊ณตํ๋ค๋ฉด json string์๋ต์ด ์จ๋ค.
http://ORDERS_EXTERNAL_IP/api/orders
http://PRODUCTS_EXTERNAL_IP/api/products
Task 5. Configure and deploy the Frontend microservice
Orders์ Products ๋ง์ดํฌ๋ก์๋น์ค๋ฅผ ๋ถ๋ฆฌํ์์ผ๋, ๋ง์ฐฌ๊ฐ์ง๋ก ํ๋ก ํธ์๋ ์ฑ๋ ๋ง์ดํฌ๋ก์๋น์ค๋ก ๋ถ๋ฆฌํ ์ฐจ๋ก์ด๋ค. ํ๋ก ํธ์๋ ์๋น์ค๊ฐ ๊ฐ orders/products ์๋น์ค๋ฅผ ๊ฐ๋ฆฌํค๊ฒ ํ๊ณ , ์๋ก ๋ฐฐํฌํ๋ค.
์๋ก ๋ง์ดํฌ๋ก์๋น์ค IP ์ฃผ์๋ก ๋งคํํด์ฃผ๊ธฐ์ํด envํ์ผ์ nano ์๋ํฐ๋ก ์์ ํ๋ค.
cd ~/monolith-to-microservices/react-app
nano .env
์๋์ ๊ฐ์ด ์๋ก์ด ์ฃผ์๋ก ๋ณ๊ฒฝํด์ค๋ค.
REACT_APP_ORDERS_URL=http://<ORDERS_IP_ADDRESS>/api/orders
REACT_APP_PRODUCTS_URL=http://<PRODUCTS_IP_ADDRESS>/api/products
์ปจํ ์ด๋๋ผ์ด์ง ํ๊ธฐ์ด์ ์ ๋จผ์ ์ฑ์ ๋น๋ํ๋ค.
npm run build
Task 6. Create a containerized version of the Frontend microservice
์์์ ํ๋ ๊ฒ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ํ๋ก ํธ์๋ ์ฑ๋ ๋๊ฐ์ด ์ปจํ ์ด๋ํํ๋ค.
- Service root folder: ~/monolith-to-microservices/microservices/src/frontend
- Repo: gcr.io/${GOOGLE_CLOUD_PROJECT}
- Image name: Frontend Identifier
- Image version: 1.0.0
Cloud Build๋ฅผ ์ฌ์ฉํด์ ํ๋ก ํธ์๋ ์๋น์ค๋ฅผ ํจํค์งํ๊ณ , ๋์ปค ์ด๋ฏธ์ง๋ฅผ Artifact Registry์ ํธ์ฌํ๋ค.
cd ~/monolith-to-microservices/microservices/src/frontend
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/{Frontend Identifier}:1.0.0 .
Task 7. Deploy the Frontend microservice
ํ๋ก ํธ์๋ ์๋น์ค๋ฅผ Kubernetes์ ๋ฐฐํฌํ๋ ๊ฒ๋ ์์์์ ๊ฐ์ ํ๋ก์ธ์ค์ด๋ค.
- Cluster name: Cluster Name
- Container name: Frontend Identifier
- Container version: 1.0.0
- Application port: 8080
- Externally accessible port: 80
ํ๋ก ํธ ์ฑ์ GKE ํด๋ฌ์คํฐ์ ๋ฐฐํฌํ๋ค.
kubectl create deployment {Frontend Identifier} --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/{Frontend Identifier}:1.0.0
GKE๊ฐ ์๋น์ค ๋ฆฌ์ค์ค์ external IP์ฃผ์๋ฅผ ํ ๋นํ๊ฒ ํ๋ค.
kubectl expose deployment {Frontend Identifier} --type=LoadBalancer --port 80 --target-port 8080
์ด์ ํด๋น external IP๋ก ์ ์ํ๋ฉด ์น์ฌ์ดํธ๊ฐ ์ ์๋ํ๋๊ฑธ ๋ณผ ์์๋ค. ์ด์ Products๋ฉ๋ด, Orders๋ฉ๋ด๋ ๊ฐ๊ฐ ์๋ก์ด ๋ง์ดํฌ๋ก์๋น์ค๋ก ๊ตฌ๋๋๊ณ ์๋ค.
'Google Cloud Platform' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| Explore Generative AI with the Gemini API in Vertex AI: Challenge Lab (0) | 2025.09.24 |
|---|---|
| Set Up a Google Cloud Network (2) | 2025.08.23 |
| Develop GenAI Apps with Gemini and Streamlit | feat. WebSocket error (0) | 2025.08.18 |
| Introduction to Function Calling with Gemini (0) | 2025.08.11 |
| Getting Started with the Gemini API in Vertex AI with cURL / REST API (1) | 2025.08.07 |