- enable the Kubernetes Engine API
gcloud services enable container.googleapis.com
- buat cluster GKE dengan nama
fancy-cluster
dengan 3 nodegcloud container clusters create fancy-cluster --num-nodes 3
- cek cluster yang sudah dibuat
gcloud compute instances list
- cek cluster yang sudah dibuat juga bisa dengan menuju ke console GCP > Kubernetes Engine > Clusters
- clone repository
cd ~ git clone https://github.com/googlecodelabs/monolith-to-microservices.git
- install dependencies
cd ~/monolith-to-microservices ./setup.sh
- pastikan menggunakan versi npm terbaru
nvm install --lts
- jalankan aplikasi
cd ~/monolith-to-microservices/monolith npm start
- lihat hasilnya di browser dengan membuka web preview > preview on port 8080
- pastikan cloud build API sudah di enable
gcloud services enable cloudbuild.googleapis.com
- build image dengan cloud build
cd ~/monolith-to-microservices/monolith gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/monolith:1.0.0 .
- deploy container ke GKE
kubectl create deployment monolith --image=gcr.io/${GOOGLE_CLOUD_PROJECT}/monolith:1.0.0
-
cek deployment
kubectl get all
# Show pods kubectl get pods # Show deployments kubectl get deployments # Show replica sets kubectl get rs #You can also combine them kubectl get pods,deployments
-
bisa juga Navigation menu > Kubernetes Engine > Workloads.
-
delete pods
kubectl delete pod/<POD_NAME>
- expose deployment
kubectl expose deployment monolith --type=LoadBalancer --port 80 --target-port 8080
- cek service
kubectl get service
- scale deployment dengan 3 replica
kubectl scale deployment monolith --replicas=3
- cek deployment
kubectl get all
- edit file
cd ~/monolith-to-microservices/react-app/src/pages/Home mv index.js.new index.js
- rebuild app
cd ~/monolith-to-microservices/react-app npm run build:monolith
- build image
cd ~/monolith-to-microservices/monolith
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/monolith:2.0.0 .
- update deployment
kubectl set image deployment/monolith monolith=gcr.io/${GOOGLE_CLOUD_PROJECT}/monolith:2.0.0
- cek deployment
kubectl get pods
- jalankan app
npm start
- delete git repository
rm -rf ~/monolith-to-microservices
- delete google container registry images
# Delete the container image for version 1.0.0 of the monolith gcloud container images delete gcr.io/${GOOGLE_CLOUD_PROJECT}/monolith:1.0.0 --quiet # Delete the container image for version 2.0.0 of the monolith gcloud container images delete gcr.io/${GOOGLE_CLOUD_PROJECT}/monolith:2.0.0 --quiet
- Delete Google Cloud Build artifacts from Google Cloud Storage
# The following command will take all source archives from all builds and delete them from cloud storage # Run this command to print all sources: # gcloud builds list | awk 'NR > 1 {print $4}' gcloud builds list | grep 'SOURCE' | cut -d ' ' -f2 | while read line; do gsutil rm $line; done
- Delete GKE Service:
kubectl delete service monolith kubectl delete deployment monolith
- Delete GKE Cluster:
gcloud container clusters delete fancy-cluster