Skip to content

Latest commit

 

History

History
151 lines (144 loc) · 4 KB

File metadata and controls

151 lines (144 loc) · 4 KB

GSP699 - Migrating a Monolithic Website to Microservices on Google Kubernetes Engine

Task 1. Clone the source repository

  1. 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

  1. Enable container API
    gcloud services enable container.googleapis.com
  2. Buat GKE cluster dengan 3 node
    gcloud container clusters create fancy-cluster --num-nodes 3 --machine-type=e2-standard-4
  3. Cek cluster
    gcloud compute instances list

Task 3. Deploy the existing monolith

  1. Deploy ke GKE Cluster
    cd ~/monolith-to-microservices
    ./deploy-monolith.sh

Accessing the monolith

  1. Cek ip external
    kubectl get services monolith
    akses dengan ip external
    http://<EXTERNAL-IP>:80

Task 4. Migrate orders to a microservice

  1. Build docker container
    cd ~/monolith-to-microservices/microservices/src/orders
    gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/orders:1.0.0 .
  2. Deploy ke GKE
    kubectl create deployment orders --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/orders:1.0.0
  3. Cek deployment
    kubectl get all
  4. Expose service
    kubectl expose deployment orders --type=LoadBalancer --port 80 --target-port 8081
  5. Akses service
    kubectl get services orders

Reconfigure the monolith

  1. Gunakan nano editor untuk edit atau pake code editor juga sabi
    cd ~/monolith-to-microservices/react-app
    nano .env.monolith
  2. Ubah isi file .env.monolith
    REACT_APP_ORDERS_URL=http://<ORDERS_IP_ADDRESS>/api/orders
    REACT_APP_PRODUCTS_URL=/service/products
  3. Deploy ulang monolith
    npm run build:monolith
  4. Buat image baru
    cd ~/monolith-to-microservices/monolith
    gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/monolith:2.0.0 .
  5. Deploy ke GKE
    kubectl set image deployment/monolith monolith=gcr.io/${GOOGLE_CLOUD_PROJECT}/monolith:2.0.0

Task 5. Migrate Products to microservice

  1. Buat docker container
cd ~/monolith-to-microservices/microservices/src/products
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/products:1.0.0 .
  1. Deploy ke GKE
kubectl create deployment products --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/products:1.0.0
  1. Expose service
kubectl expose deployment products --type=LoadBalancer --port 80 --target-port 8082
  1. Akses service
kubectl get services products

Reconfigure the monolith

  1. 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
  2. Rebuild monolith
    npm run build:monolith
  3. Buat image baru
    cd ~/monolith-to-microservices/monolith
    gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/monolith:3.0.0 .
  4. Deploy ke GKE
    kubectl set image deployment/monolith monolith=gcr.io/${GOOGLE_CLOUD_PROJECT}/monolith:3.0.0

Task 6. Migrate frontend to microservice

  1. copy .env.monolith to .env
    cd ~/monolith-to-microservices/react-app
    cp .env.monolith .env
    npm run build
  2. Buat docker container
    cd ~/monolith-to-microservices/microservices/src/frontend
    gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/frontend:1.0.0 .
  3. Deploy ke GKE
    kubectl create deployment frontend --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/frontend:1.0.0
  4. Expose service
    kubectl expose deployment frontend --type=LoadBalancer --port 80 --target-port 8080