Key features of GCP - Google Kubernetes Engine (GKE)
- Orchestration
- Auto Scaling - Scale containers based on demand
- Service Discovery - Help microservices find one another
- Load Balancer - Distribute load among multiple instances of a microservice
- Self Healing - Do health checks and replace failing instances
- Zero Downtime Deployments - Release new versions without downtime
-
You can pull docker image to your OWN local machine
-Exchange microservice docker pull jamesfloatingmarket1508/mss-currency-exchange-k8s:0.0.11-SNAPSHOT - Conversion microservice docker pull jamesfloatingmarket1508/mss-currency-conversion-k8s:0.0.11-SNAPSHOT
-
Run docker containers in your local manchine by Docker Deamon, for testing before doing any deployment.
docker run -p 8000:8000 jamesfloatingmarket1508/mss-currency-exchange-k8s:0.0.11-SNAPSHOT docker run -p 8100:8100 jamesfloatingmarket1508/mss-currency-conversion-k8s:0.0.11-SNAPSHOT
-
Test command on local:
curl http://localhost:8000/currency-exchange/from/USD/to/GBP curl http://localhost:8100/feign/currency-conversion/from/USD/to/GBP/quanlity/70
Create trial Google Kubernetes Cluster
![Screenshot 2023-06-28 at 14 52 06](https://private-user-images.githubusercontent.com/11584601/249499967-5d3c69d4-7c17-430a-b55b-a2ea9273e4ff.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1NzM4MzcsIm5iZiI6MTcyNDU3MzUzNywicGF0aCI6Ii8xMTU4NDYwMS8yNDk0OTk5NjctNWQzYzY5ZDQtN2MxNy00MzBhLWI1NWItYTJlYTkyNzNlNGZmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDA4MTIxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY5ZTJkNzIzZWIzNjdmNWJjNjg5ZTg5MWRkMTgwM2Q0ZjEzMjJkNWM4NWJiNTcxY2YwN2YwMzY2NWUzOWZkYjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.goJDCE1TyBQnWodfwdzdc8B4nDfEqQoqETaYnIYtAZ8)
Step 1: Make sure you have GCloud be installed in your PC.
https://cloud.google.com/sdk/docs/install
Step 2: Authentication with Google Account that has Kubernetes Cluster.
gcloud container clusters get-credentials {your cluster name} --zone us-central1-c --project {project id}
a) Manual:
a1) Exchange service
kubectl create deployment currency-exchange --image=jamesfloatingmarket1508/mss-currency-exchange-k8s:0.0.11-SNAPSHOT
kubectl expose deployment currency-exchange --type=LoadBalancer --port=8000
![Screenshot 2023-06-28 at 15 00 40](https://private-user-images.githubusercontent.com/11584601/249505589-ed209d67-f1dd-4746-a435-d06761e78e20.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1NzM4MzcsIm5iZiI6MTcyNDU3MzUzNywicGF0aCI6Ii8xMTU4NDYwMS8yNDk1MDU1ODktZWQyMDlkNjctZjFkZC00NzQ2LWE0MzUtZDA2NzYxZTc4ZTIwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDA4MTIxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcxMWI3OTVhYmYzMTczYzk3ODhjMTMwMmI4MzFmODE4NjM5ZWIzNzgzODkyYjZhYzdmYWIzNDZkOGNkMjI3YWImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.65IDyW6Xy5PasOGh48yYQMUvhCBaH8xIOaqsJNOGU_8)
Terminal run: kubectl get service
Test again: curl http://EXTERNAL-IP:port/currency-exchange/from/USD/to/GBP
Public IP: curl http://34.31.250.64:8000/currency-exchange/from/USD/to/GBP
a2) Conversion service
kubectl create deployment currency-conversion --image=jamesfloatingmarket1508/mss-currency-conversion-k8s:0.0.11-SNAPSHOT
kubectl expose deployment currency-conversion --type=LoadBalancer --port=8100
curl http://35.202.191.27:8100/feign/currency-conversion/from/USD/to/GBP/quanlity/123
b) How about deploy automatic by yaml file to Google Kubernetes Engine Open Terminal
Step 1)
cd to exchange-currency-k8s directory
kubectl apply -f deployment.yaml
![Screenshot 2023-06-28 at 15 16 44](https://private-user-images.githubusercontent.com/11584601/249513361-f49a5980-fec8-4e1b-88eb-f60f97642e8c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1NzM4MzcsIm5iZiI6MTcyNDU3MzUzNywicGF0aCI6Ii8xMTU4NDYwMS8yNDk1MTMzNjEtZjQ5YTU5ODAtZmVjOC00ZTFiLTg4ZWItZjYwZjk3NjQyZThjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDA4MTIxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQwMGUyYzRjMzNmOWMxMzFhOGJmMTBiZTY2ODJhNzZiZTVhMzZmMDhhN2NiNzlmNGE4MzU0MjVhNTQ3NWYxMGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.W2pqcCS61ScrmkP2MWKAgi4GDLy5AQlQ4mZt7ZwYq7Q)
Step 2)
cd to conversion-currency-k8s directory
kubectl apply -f deployment.yaml
![Screenshot 2023-06-28 at 16 19 50](https://private-user-images.githubusercontent.com/11584601/249531453-e17002fa-f4e3-40c0-9dc8-e0a243cc1716.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1NzM4MzcsIm5iZiI6MTcyNDU3MzUzNywicGF0aCI6Ii8xMTU4NDYwMS8yNDk1MzE0NTMtZTE3MDAyZmEtZjRlMy00MGMwLTlkYzgtZTBhMjQzY2MxNzE2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDA4MTIxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEyN2I4NjdlNzI2NTZmZWZkMzMwNjk3YzBmNjFkZDEyYWUzODhlMzk3ZTZjNTIwZjA3ZWFkODU2ZGI3MjBmMDImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.2EZ0XyOV-aQz_UUXJCGmnanjkme6saGfMYtyfxJsGIo)
kubectl get hpa
kubectl top node
kubectl top pods
kubectl get pods --all-namespaces
-
Stress test ping API every 0.01 second to make the CPU usage hits 20%
watch -n 0.01 curl http://35.202.191.27:8100/feign/currency-conversion/from/USD/to/GBP/quanlity/123 watch -n 0.01 curl http://35.202.191.27:8100/feign/currency-conversion/from/USD/to/GBP/quanlity/456 watch -n 0.01 curl http://35.202.191.27:8100/feign/currency-conversion/from/USD/to/GBP/quanlity/789
![Screenshot 2023-06-28 at 16 28 02](https://private-user-images.githubusercontent.com/11584601/249534658-50442a7c-283b-4eb7-b95e-9b03bc5ea273.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1NzM4MzcsIm5iZiI6MTcyNDU3MzUzNywicGF0aCI6Ii8xMTU4NDYwMS8yNDk1MzQ2NTgtNTA0NDJhN2MtMjgzYi00ZWI3LWI5NWUtOWIwM2JjNWVhMjczLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDA4MTIxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTViMmYyY2Y0ZTY4YmQwNmNiNzJkMmJhMWJkYjU2MDYxNzNmYWZiYWQ2NjVjNjczODc2YzUxMTdjZmMwNTFkZTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.-CjW7MmJ6K8Y_0osmhVWZirp0rMdQl6VmbsChAcUVCM)
![Screenshot 2023-06-28 at 16 45 25](https://private-user-images.githubusercontent.com/11584601/249539653-8f5fa587-d7e5-4a5c-b51f-d432d0d9e4f2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1NzM4MzcsIm5iZiI6MTcyNDU3MzUzNywicGF0aCI6Ii8xMTU4NDYwMS8yNDk1Mzk2NTMtOGY1ZmE1ODctZDdlNS00YTVjLWI1MWYtZDQzMmQwZDllNGYyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDA4MTIxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTkzZWNhYjAzZWRjMWUyYzE1NTNkZTE4ZWE2ZWU1NGVkMzhiZmRlNGU3OTc4ZjdjZmFiZDI0NWIwYzA5ZGY1NjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.TImR-L2-tNfOUrcpsdB17gqbXKveeO0dSw6QhQ_o-YM)
![Screenshot 2023-06-28 at 16 58 39](https://private-user-images.githubusercontent.com/11584601/249543500-253b693a-e920-4c66-ae94-d2a6632581f4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1NzM4MzcsIm5iZiI6MTcyNDU3MzUzNywicGF0aCI6Ii8xMTU4NDYwMS8yNDk1NDM1MDAtMjUzYjY5M2EtZTkyMC00YzY2LWFlOTQtZDJhNjYzMjU4MWY0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDA4MTIxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRmZDg4MTYzZWUzNmE2YWYzNDc3MDc3ZWNjZGYyYzEwNDc3MzQ1NWY2YTVkNmE0MDYyMGJkZTc1YTcwYTZjZDgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.UPWvOnrX0lfeqS3ADNRakwxV_v-12iTAhj5NkqUtXNw)