Microservice that acts as the unique access from the front-ends services to the back-end services.
The purpose to have a unique gateway access is for security purpose that is a common pattern in distributed architectures, used to decouple the internal API from the clients (fornt-end).
Other purposes are for monitor and resilence.
We chose Spring Cloud Gateway to build a gateway-service and implement an API gateway. We improve resilence of the system by configuring circuit breaker with Spring Cloud Circuit Breaker, defining rate limiters with Spring Data Redis Reactive (where we store web sessions).
note: Vaadin flow and Hilla has its own mechanism for store web sessions, but in order to include rate limiters as a centralized component (i.e., for several micro-fonts) some how we repeat this functionality.
This microservice can have external access to the application running in a Kubernetes cluster by relying on the Kubernetes Ingress API.
./gradlew bootBuildImage
./gradlew bootBuildImage \
--imageName ghcr.io/rlegorreta/gateway-service \
--publishImage \
-PregistryUrl=ghcr.io \
-PregistryUsername=rlegorreta \
-PregistryToken=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
To publish the image to GitHub from the IDE IntelliJ a file inside the directory .github/workflows/commit-stage.yml
was created.
To validate the manifest file for kubernetes run the following command:
kubeval --strict -d k8s
This file compiles de project, test it (for this project is disabled for some bug), test vulnerabilities running skype, commits the code, sends a report of vulnerabilities, creates the image and lastly push the container image.
For detail information see .github/workflows/commit-stage.yml
file.
docker run \
--net ailegorretaNet \
-p 8071:8071 \
-e SPRING_PROFILES_ACTIVE=local \
gateway-service
Or a better method use the docker-compose
tool. Go to the directory ailegorreta-deployment/docker-platform
and run the command:
docker-compose up
If we do not use the Tilt
tool nd want to do it manually, first we need to create the image:
Fist step:
./gradlew bootBuildImage
Second step:
Then we have to load the image inside the minikube executing the command:
image load ailegorreta/gateway-service --profile ailegorreta
To verify that the image has been loaded we can execute the command that lists all minikube images:
kubectl get pods --all-namespaces -o jsonpath="{..image}" | tr -s '[[:space:]]' '\n' | sort | uniq -c\n
Third step:
Then execute the deployment defined in the file k8s/deployment.yml
with the command:
kubectl apply -f k8s/deplyment.yml
And after the deployment can be deleted executing:
kubectl apply -f k8s/deplymengt.yml
Fourth step:
For service discovery we need to create a service applying with the file: k8s/service.yml
executing the command:
kubectl apply -f k8s/service.yml
And after the process we can delete the service executing:
kubectl deltete -f k8s/service.yml
Fifth step:
If we want to use the project outside kubernetes we have to forward the port as follows:
kubectl port-forward service/config-service 8071:80
Appendix:
If we want to see the logs for this pod
we can execute the following command:
kubectl logs deployment/config-service
To avoid all these boilerplate steps is much better and faster to use the Tilt
tool as follows: first create see the
file located in the root directory of the proyect called TiltFile
. This file has the content:
# Tilt file for config-service
# Build
custom_build(
# Name of the container image
ref = 'gategay-service',
# Command to build the container image
command = './gradlew bootBuildImage --imageName $EXPECTED_REF',
# Files to watch that trigger a new build
deps = ['build.gradle', 'src']
)
# Deploy
k8s_yaml(['k8s/deployment.yml', 'k8s/service.yml'])
# Manage
k8s_resource('config-service', port_forwards=['8071'])
To execute all five steps manually we just need to execute the command:
tilt up
In order to see the log of the deployment process please visit the following URL:
http://localhost:10350
Or execute outside Tilt the command:
kubectl logs deployment/gateway-service
In order to undeploy everything just execute the command:
tilt down
To run inside a docker desktop the microservice need to use http://confsrv:8072 path
This microservice uses the recent Spring Gateway :
- Spring Boot Gateway
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Eureka Discovery Client
- Config Client Quick Start
- Spring Boot Actuator
https://tanzu.vmware.com/developer/guides/observability-reactive-spring-boot-3/
Baeldung:
https://www.baeldung.com/spring-boot-3-observability
Feel free to reach out to AI Legorreta on web page.
Version: 2.0.0 ©LegoSoft Soluciones, S.C., 2023