how to build and run the entire project (it also builds all images before running):
- make sure to have docker installed and using dockerhub with kubernetes enabled
- make sure to have go (version 1.22 or higher) installed and 'hey' installed (https://github.com/rakyll/hey)
go install github.com/rakyll/hey@latest - move to the project root directory (the directory where this README.md is located)
- run the following commands to stop any running containers and remove existing images and volumes, then build and run the project:
If you want to deploy the project on kubernets, run the following commands (then wait some minutes to make sure everything is up and running correctly before running other commands):
kubectl delete -f kubernetes/
kubectl apply -f kubernetes/to only delete containers
kubectl delete -f k8s-manifest.yamlto only apply the manifest and run the project:
kubectl apply -f k8s-manifest.yamlto test if the application is running, you can use the following command (windows), if linux remove the .exe. It sends an health check request to the API Gateway of the application:
curl.exe -X GET http://localhost:31080/healthor
curl http://localhost:31080/healthto check if the application reaches the service from api-gateway:
curl.exe http://localhost:31080/service/healthto check all endpoints that can be reached from the API Gateway, you can use the following command:
curl.exe http://localhost:31080/routeto get metrics from API gateway
curl.exe http://localhost:31080/metricsto get metrics from the service
curl.exe http://localhost:31080/service/metricsit is also possible to query prometheus via its browser GUI, connecting to "http://localhost:31090/"
To test the autoscaler, first check if the metrics server is running:
kubectl top nodes
kubectl top pods -n monitoring-appthen run this command on another terminal to watch the horizontal pod autoscaler for the API Gateway:
kubectl get hpa -n monitoring-app --watchthen go back to previous terminal and run this command that uses 'hey' to runs 50 workers that concurrently send requests for 2 minutes to the health endpoint of the API Gateway and then prints metrics about the requests:
hey -c 50 -z 2m http://localhost:31080/healthyou should be seeing the number of pods for the API Gateway increasing and decreasing based on the requests sent by 'hey' in the terminal where you ran the watch command.
You can also run the same command for the service:
hey -c 50 -z 2m http://localhost:31080/service/healthIf you want to use docker, run those commands instead:
docker-compose down --rmi all -v
docker-compose up --build -dto build and run without removing images:
docker-compose down -v
docker-compose up --build -dto only build the project and run it in detached mode:
docker-compose up --build -dto only stop the project and remove all containers, networks, images and volumes created by docker-compose up:
docker-compose down --rmi all -vto only stop the project and remove only volumes and containers:
docker-compose down -vto test if the application is running, you can use the following command (windows), if linux remove the .exe. It sends an health check request to the API Gateway of the application:
curl.exe -X GET http://localhost:8080/healthor
curl http://localhost:8080/healthto check if the application reaches the service from api-gateway:
curl.exe http://localhost:8080/service/healthto check all endpoints that can be reached from the API Gateway, you can use the following command:
curl.exe http://localhost:8080/routeto get metrics from API gateway
curl.exe http://localhost:8080/metricsto get metrics from the service
curl.exe http://localhost:8080/service/metricsit is also possible to query prometheus via its browser GUI, connecting to "http://localhost:9090/"