This repository was created by Banzai Cloud Pipeline. Spotguides provide automated configuration, logging, monitoring, security, and scaling for your application stacks.
Every time you make changes to the source code and update the master
branch, the CI/CD pipeline will be triggered to test, validate and update the deployment of your application. Check the .pipeline.yaml
file for CI/CD steps.
Requirements:
- Docker
- Docker for Desktop
- skaffold and its dependencies
A local Kubernetes cluster must be running (eg. Docker for Desktop).
# verify the Kubernetes context
$ kubectl config get-contexts
# expected output
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* docker-for-desktop docker-for-desktop-cluster docker-for-desktop
# build the Docker image and deploy via helm
$ cd .banzaicloud
$ skaffold run
This will build the application and install all the components to Kubernetes.
Requirements:
Commands:
mvn clean package
Requirements:
Commands:
DOCKER_REPO=spotguide-spring-boot DOCKER_TAG=latest mvn compile jib:dockerBuild
This spotguide uses spring-boot-devtools, it is a utility dependency that will monitor for any changes in your classpath and automatically restart your server.
Using local Spring Boot and with the SQL compatible H2 database:
Requirements:
Commands:
mvn spring-boot:run
Using Docker and Docker Compose:
Requirements:
Commands:
# start dependencies
docker-compose up -d
# build image
DOCKER_REPO=spotguide-spring-boot DOCKER_TAG=latest mvn compile jib:dockerBuild
# start application in development mode
mvn spring-boot:run
Our Spring Boot Actuator
library and Spring Cloud Kubernetes together provides all the essential features to prepare your Spring Boot application truly ready for production on Kubernetes, such as:
- graceful error handling & shutdown
- structured JSON logging
- various HTTP middleware
- health checks
- metrics
name | description | default |
---|---|---|
SERVER_PORT |
Application port | 8080 |
SPRING_DATASOURCE_URL |
JDBC URL, scheme: jdbc:driver:host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]] |
|
SPRING_DATASOURCE_USERNAME |
Database user | |
SPRING_DATASOURCE_PASSWORD |
Database user password | |
SPRING_DATASOURCE_DATABASE |
Database database name |
These are the available REST endpoints in the sample application:
Kubernetes endpoint, returns basic Pod information, like name, namespace and image.
Prometheus metrics endpoint.
Health check, liveness probe endpoint. Returns 200
when the application is healthy, can reach the database.
Fetch all users.
Create a new user. The request body has the following schema:
{
"email": "",
"userName": "",
"firstName": "",
"lastName": ""
}
Fetch a user.
Update a user. The request body has the same schema as POST /api/v1/users
.
Delete a user.
You have to enable Kafka support via running it with SPRING_KAFKA_ENABLED=true
.
Fetch all Kafka messages.
Send a new message to the "spring-boot"
Kafka topic.
{
"message": "hello-spring-boot"
}
## Build and Test locally with Docker for Mac Kubernetes
DOCKER_REPO=banzaicloud/spotguide-spring-boot DOCKER_TAG=latest mvn compile jib:dockerBuild
helm dep update .banzaicloud/charts/spotguide-spring-boot
helm upgrade --install spotguide-spring-boot .banzaicloud/charts/spotguide-spring-boot --set ingress.enabled=true --set "ingress.hosts[0]=localhost" --set monitor.enabled=true --set pipeline-ingress.enabled=true
# Check the application (if Ingress not enabled)
kubectl port-forward deployment/spotguide-spring-boot 8080
# Access the Spring application
open http://localhost:[8080]
# Delete the Helm release
helm delete --purge spotguide-spring-boot
# Build the fat JAR
mvn clean package -DskipTests
SPRING_DATASOURCE_USERNAME=sparky SPRING_DATASOURCE_PASSWORD=sparky123 java -jar target/app.jar
curl -H "Content-Type: application/json" http://localhost:8080/api/v1/users -d '{"userName":"john","email":"john@doe.com"}'