GSP699 - Migrating a Monolithic Website to Microservices on Google Kubernetes Engine
Task 1. Clone the source repository
Clone the source repository
cd ~
git clone https://github.com/googlecodelabs/monolith-to-microservices.git
cd ~ /monolith-to-microservices
./setup.sh
Task 2. Create a GKE cluster
Enable container API
gcloud services enable container.googleapis.com
Buat GKE cluster dengan 3 node
gcloud container clusters create fancy-cluster --num-nodes 3 --machine-type=e2-standard-4
Cek cluster
gcloud compute instances list
Task 3. Deploy the existing monolith
Deploy ke GKE Cluster
cd ~ /monolith-to-microservices
./deploy-monolith.sh
Cek ip external
kubectl get services monolith
akses dengan ip external
Task 4. Migrate orders to a microservice
Build docker container
cd ~ /monolith-to-microservices/microservices/src/orders
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT} /orders:1.0.0 .
Deploy ke GKE
kubectl create deployment orders --image=gcr.io/${GOOGLE_CLOUD_PROJECT} /orders:1.0.0
Cek deployment
Expose service
kubectl expose deployment orders --type=LoadBalancer --port 80 --target-port 8081
Akses service
kubectl get services orders
Gunakan nano editor untuk edit atau pake code editor juga sabi
cd ~ /monolith-to-microservices/react-app
nano .env.monolith
Ubah isi file .env.monolith
REACT_APP_ORDERS_URL=http://< ORDERS_IP_ADDRESS> /api/orders
REACT_APP_PRODUCTS_URL=/service/products
Deploy ulang monolith
Buat image baru
cd ~ /monolith-to-microservices/monolith
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT} /monolith:2.0.0 .
Deploy ke GKE
kubectl set image deployment/monolith monolith=gcr.io/${GOOGLE_CLOUD_PROJECT} /monolith:2.0.0
Task 5. Migrate Products to microservice
Buat docker container
cd ~ /monolith-to-microservices/microservices/src/products
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT} /products:1.0.0 .
Deploy ke GKE
kubectl create deployment products --image=gcr.io/${GOOGLE_CLOUD_PROJECT} /products:1.0.0
Expose service
kubectl expose deployment products --type=LoadBalancer --port 80 --target-port 8082
Akses service
kubectl get services products
Ubah isi file .env.monolith
cd ~ /monolith-to-microservices/react-app
nano .env.monolith
REACT_APP_ORDERS_URL=http://< ORDERS_IP_ADDRESS> /api/orders
REACT_APP_PRODUCTS_URL=http://< PRODUCTS_IP_ADDRESS> /api/products
Rebuild monolith
Buat image baru
cd ~ /monolith-to-microservices/monolith
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT} /monolith:3.0.0 .
Deploy ke GKE
kubectl set image deployment/monolith monolith=gcr.io/${GOOGLE_CLOUD_PROJECT} /monolith:3.0.0
Task 6. Migrate frontend to microservice
copy .env.monolith to .env
cd ~ /monolith-to-microservices/react-app
cp .env.monolith .env
npm run build
Buat docker container
cd ~ /monolith-to-microservices/microservices/src/frontend
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT} /frontend:1.0.0 .
Deploy ke GKE
kubectl create deployment frontend --image=gcr.io/${GOOGLE_CLOUD_PROJECT} /frontend:1.0.0
Expose service
kubectl expose deployment frontend --type=LoadBalancer --port 80 --target-port 8080