Kubernetes ft. Spring Boot (Series) - Creating the services #1
There is life after building the jar
!
Brief
In this series we'll create a Kubernetes environment that will manage 2 simple Spring Boot applications that will communicate with each other through HTTP requests.
We'll have a calling
application and a receiver
application. A client will send a request to the calling
application, this will then send a request to the receiver
application and the response will be returned all the way to the client.
Implementation
For the sake of simplicity, the request from the client
will be passed over to the receiver
service without doing any business logic and will be returned as a response all the way back to the client
.
With the help of Spring Initializr creating the applications is quite straightforward. We'll create two Gradle
projects with Java 11 and we'll only need the Spring Web
dependency added to the projects.
Caller application
- We'll configure the server to run on port
9991
and have as a context path/caller
. So the client's requests will be sent to:http://localhost:9991/caller
- Defining the request body DTO
- It will also need a REST controller to be able to receive requests from the
client
.
- The service that will actually send the request to the
receiver
application.
Receiver application
- Server configuration for port and context path
- Creating the endpoint on the
receiver
application
Test
Simulate being the client
by sending a request through Postman to the caller
application.
To be continued
In the next post we'll deploy them to a K8s
cluster to see how we can interact with our services in a separate environment rather than localhost
. See you there!
Stay tuned! 🚀