There is an abundance of documentation available for learning Kubernetes and Spring Boot, which are not particularly new topics. I have not documented my learnings in a while, so it might be beneficial to create something for reflection and future reference. Let's begin by establishing our own environment and progressively enhancing it. We will use the following technologies, starting with the most fundamental implementations:
- JDK 22
- Springboot 3.3.2
- Podman
- minikube
At the conclusion of our journey, I will provide the sample code I have created. Let's start with a brief application development that we can deploy to our cluster. I utilized the Spring Boot initializer via sdkman to run it directly in my terminal.
sdk install springboot 3.3.1
We’ll create our microservice using the spring cli
spring init — build=maven — java-version=22 — dependencies=lombok,web — packaging=jar — artifact-id=user-service — group-id=com.sudocode user-service
We won't review every content generated by our Spring initializer; instead, we'll focus on the structure used and the API that will be exposed.
I appreciate clean architecture, which is why I always keep my structures organized to the bare minimum.
In our router, we will expose a single endpoint whose sole purpose is to return the greeting "Hello <firstName> <lastName>." We can run our application via the terminal to test if it functions correctly.
Now that our application is running, we will build our container using Podman, which functions similarly to Docker.
To build the image, use the Dockerfile provided above.
This will produce our container, which we will subsequently push to our Docker registry.
Before we push our container we’ll be testing it out to see if we have the same results as before.
Now that our application is up and running, we will push our image to our Docker registry, using Docker Hub in this instance.
Now that our image is published on Docker Hub, we will deploy our local Kubernetes cluster using Minikube. The configuration for Minikube along with Podman is available [here].
With our Minikube now up and running, we will proceed to configure our Kubernetes deployment resources along with our service.
For the time being, please adhere to the current configuration while I periodically update the guide. To deploy our first microservice within Minikube, let's execute the following command.
kubectl apply -f k8s
This applies our configuration to Minikube. Next, we will test our application and review the setup steps we followed to run Minikube using Podman. Let's forward our pod to make it accessible locally and resend the initial request.
We have successfully deployed our initial microservice in our local environment utilizing a minimal number of resources. I will be publishing an additional article that addresses the deployment of multiple microservices in AWS EKS. The source code is available here.