Team members:
Long Phan-Phuc Tran 1573950
Sahaj Bikram Malla 1563270
Group:
CloudComp44
This project demonstrates a Spring Boot application designed for deployment on Kubernetes with autoscaling, monitoring, and CI/CD integration as part of Cloud Computing course from Hochschule Fulda.
- REST API endpoints with custom metrics
- Prometheus metrics exposure via Actuator
- Docker containerization
- Unit and integration tests
- Kubernetes deployment-ready
- Autoscaling compatible
- Java 17
- Maven 3.8+
- Docker
- Kubernetes cluster (or Docker Desktop for local testing)
- Helm (for Prometheus/Grafana installation)
git clone https://github.com/longtran112/springboot-autoscale.git
cd springboot-appmvn clean packagejava -jar target/*.jar# Hello endpoint
curl http://localhost:8080/
# API endpoint
curl http://localhost:8080/api
# Increment custom metric
curl http://localhost:8080/increment
# Health check
curl http://localhost:8080/actuator/health
# Prometheus metrics
curl http://localhost:8080/actuator/prometheus# Run all tests
mvn test
# Run specific test class
mvn -Dtest=HelloControllerTest testdocker build -t longtran112/springboot-app:latest .docker run -p 8080:8080 longtran112/springboot-appThe application is designed to be deployed to Kubernetes using the provided Terraform configuration.
- Horizontal Pod Autoscaler (HPA)
- Prometheus metrics scraping
- Liveness and readiness probes
- Resource limits and requests
| Variable | Default | Description |
|---|---|---|
MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE |
health,metrics,prometheus |
Actuator endpoints to expose |
SERVER_PORT |
8080 |
Application port |
The application exposes Prometheus metrics at:
http://<pod-ip>:8080/actuator/prometheus
To enable custom metrics:
- Add dependencies in
pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>- Configure in
application.properties:
management.endpoints.web.exposure.include=health,metrics,prometheus
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=trueTwo approaches are implemented: CPU-Based Scaling (HPA):
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
spec:
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
minReplicas: 1
maxReplicas: 10HTTP Request-Based Scaling (KEDA + Prometheus): KEDA ScaledObject tracks HTTP requests per second:
triggers:
- type: prometheus
metadata:
metricName: http_requests_total
threshold: "100" # Scale if >100 req/sec/pod## CI/CD IntegrationThe application is ready for Jenkins CI/CD pipelines with:
- Docker image building
- Push to DockerHub and Artifactory
- Kubernetes deployment
- Checkout source code
- Run tests with
mvn test - Build Docker image
- Push to DockerHub
- Push to Artifactory
- Deploy to Kubernetes cluster
The application exposes metrics for:
- HTTP request timings
- JVM metrics
- Custom business metrics
- System resource usage
- Spring Boot Statistics: ID 6756
- JVM Micrometer: ID 4701
- Kubernetes Cluster Monitoring: ID 3119