A simple Spring Boot application written in Kotlin that demonstrates containerized deployment to Kubernetes using Spring Boot's built-in Docker image building capabilities.
This project showcases a modern containerized deployment workflow:
- Spring Boot 3.5.5 with Kotlin
- Docker image creation using Spring Boot's
build-image
goal (Cloud Native Buildpacks) - Kubernetes deployment with proper health checks and resource management
- Container registry integration for image distribution
- Language: Kotlin
- Framework: Spring Boot 3.5.5
- Java Version: 21
- Main Endpoint:
GET /hello
→ Returns "Hello world!" - Health Checks: Spring Boot Actuator endpoints for liveness and readiness
The application uses Spring Boot's spring-boot:build-image
Maven goal, which leverages Cloud Native Buildpacks to create optimized Docker images without requiring a Dockerfile.
Configuration (from pom.xml:62-66
):
<configuration>
<image>
<name>soudmaijer/helloworld</name>
<createdDate>${maven.build.timestamp}</createdDate>
</image>
</configuration>
This project uses a pre-created Docker Hub repository: soudmaijer/helloworld
To create your own repository:
- Create Docker Hub account at https://hub.docker.com
- Create a new repository:
- Click "Create Repository"
- Choose repository name (e.g.,
your-username/helloworld
) - Set visibility (public/private)
- Update configuration in
pom.xml
:<image> <name>your-username/helloworld</name> <createdDate>${maven.build.timestamp}</createdDate> </image>
- Update Kubernetes deployment in
k8s/resources/deployment.yaml
:image: your-username/helloworld:latest
-
Build the Docker image:
./mvnw spring-boot:build-image
-
Push to registry (requires Docker Hub login):
docker login docker push soudmaijer/helloworld:latest
-
Deploy to Kubernetes:
cd k8s && ./deploy.sh
-
Test the application:
curl http://localhost/hello # Expected response: "Hello world!"
sequenceDiagram
participant Dev as Developer
participant Maven as Maven Build
participant CNB as Cloud Native Buildpacks
participant Registry as Container Registry
participant K8s as Kubernetes
participant Pod as Application Pod
Dev->>Maven: ./mvnw spring-boot:build-image
Maven->>CNB: Invoke buildpack
CNB->>CNB: Analyze source code
CNB->>CNB: Build optimized layers
CNB-->>Maven: Docker image created
Dev->>Registry: docker push soudmaijer/helloworld:latest
Registry-->>Dev: Image pushed successfully
Dev->>K8s: kubectl apply -f deployment.yaml
K8s->>Registry: Pull image
Registry-->>K8s: Image downloaded
K8s->>Pod: Create pod with image
Pod->>Pod: Start Spring Boot app
Pod-->>K8s: Readiness probe ✓
Pod-->>K8s: Liveness probe ✓
K8s-->>Dev: Deployment ready
- Replicas: 1 instance
- Image:
soudmaijer/helloworld:latest
- Image Pull Policy: Always (ensures latest version)
- Container Port: 8080
resources:
requests:
memory: "756Mi"
cpu: "250m"
limits:
memory: "1024Mi"
cpu: "500m"
Liveness Probe:
- Endpoint:
/actuator/health/liveness
- Initial Delay: 30 seconds
- Check Interval: 10 seconds
Readiness Probe:
- Endpoint:
/actuator/health/readiness
- Initial Delay: 10 seconds
- Check Interval: 5 seconds
- Type: LoadBalancer
- External Port: 80
- Target Port: 8080 (application port)
- No Dockerfile required - Cloud Native Buildpacks handle optimization
- Layered images - Efficient caching and smaller updates
- Security patches - Buildpacks include latest base image security updates
- Consistent builds - Reproducible across environments
- High availability - Pod restart on failure
- Resource management - CPU and memory limits prevent resource exhaustion
- Health monitoring - Automatic restart of unhealthy pods
- Load balancing - Service distributes traffic across replicas
- Zero-downtime deployments - Rolling updates with readiness checks
.
├── src/
│ ├── main/kotlin/nl/sourcelabs/helloworld/
│ │ └── HelloworldApplication.kt
│ └── test/kotlin/
├── k8s/
│ ├── deploy.sh
│ └── resources/
│ └── deployment.yaml
├── pom.xml
└── README.md
This setup provides a robust, production-ready deployment pipeline for Spring Boot applications in Kubernetes environments.