Build a Website on Google Cloud
gcloud config set compute/zone us-central1-a
Task 1
Download the monolith code
git clone https://github.com/googlecodelabs/monolith-to-microservices.git
cd monolith-to-microservices
./setup.sh
Build your container
gcloud services enable cloudbuild.googleapis.com
cd ~/monolith-to-microservices/monolith
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/fancytest:1.0.0 .
Task 2
Create a Kubernetes cluster
gcloud services enable container.googleapis.com
gcloud container clusters create fancy-cluster --num-nodes 3
Deploy the application
kubectl create deployment fancytest \--image=gcr.io/${GOOGLE_CLOUD_PROJECT}/fancytest:1.0.0
kubectl expose deployment fancytest --type=LoadBalancer --port 80 --target-port 8080
Task 3
Create a containerized version of orders and product Microservices
cd ~/monolith-to-microservices/microservices/src/orders
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/orders:1.0.0 .
cd ~/monolith-to-microservices/microservices/src/products
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/products:1.0.0 .
Task 4
Deploy the new microservices
Orders
cd ~/monolith-to-microservices/microservices/src/orders
kubectl create deployment orders --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/orders:1.0.0
kubectl expose deployment orders --type=LoadBalancer --port 80 --target-port 8081
Products
cd ~/monolith-to-microservices/microservices/src/products
kubectl create deployment products --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/products:1.0.0
kubectl expose deployment products --type=LoadBalancer --port 80 --target-port 8082
kubectl get services
Task 5
cd ~/monolith-to-microservices/react-app
nano .env
When the editor opens, your file should look like this:
REACT_APP_ORDERS_URL=/service/orders
REACT_APP_PRODUCTS_URL=/service/products
Replace the REACT_APP_ORDERS_URL and REACT_APP_PRODUCTS_URL
to the new format while replacing with your Orders and Products
microservice IP address so it matches below:
REACT_APP_ORDERS_URL=http://<ORDERS_IP_ADDRESS>/api/orders
REACT_APP_PRODUCTS_URL=http://<PRODUCTS_IP_ADDRESS>/api/products
npm run build
Create a containerized version of the Frontend microservice
cd ~/monolith-to-microservices/microservices/src/frontend
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/frontend:1.0.0 .
Task 6
Deploy the Frontend microservice
kubectl create deployment frontend --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/frontend:1.0.0
kubectl expose deployment frontend --type=LoadBalancer --port 80 --target-port 8080
Last updated
Was this helpful?