This repository holds a sample REST service used in most of the https://github.com/k8spatterns/examples/[examples] for the book "Kubernetes Patterns" by https://github.com/bibryam[Bilgin Ibryam] and https://github.com/rhuss[Roland Huß].
It's a simple Spring Boot service with a handful of endpoints used to demonstrate Kubernetes concepts.
You can start it locally with with ./mvnw -pl spring spring-boot:run
footnote:[Instead of the Maven wrapper mvnw
you can also use a locally installed mvn
] and get a random number:
In order to create a Docker image, just use ./mvnw -pl spring package docker:build
.
You can easly change the Docker repository and push it to your own account with -Dimage.repo
:
[cols="1,1,5,2", options="header"] |=== | Property | Env Var | Description | Pattern
version |
---|
Version of this application, created during build |
Declarative Deployment |
| log.file | LOG_FILE | Path to a log file. If set, the write out the generated response values into a CSV file | many
| log.url | LOG_URL | If given, send out an HTTP request with the results of a random number generation | Ambassador
| build.type | BUILD_TYPE | Add some informations about how the image has been built | Image Builder
| pattern | PATTERN | Descriptive label used in environment variables | Envvar Configuration, Configuration Resource
| seed | SEED | Seed number to initialize the random number generator. Must be a long. | Configuration Resource
|===
[cols="1,5,2", options="header"] |=== | Endpoint | Description | Pattern
| / | Return a random number and a unique id of this service | many
| /info | Return information about configuration and system | many
| /memory-eater | Allocate an array for eating up heap memory. Use parameter "mb" to specify the size in MegaByte | Predictable Demands
| /toggle-live
| Toggle the status of the Sprint Boot's actuator health check between UP
and DOWN
| Health Probe
| /toggle-ready | Add or remove the local file which indicates readiness of this service | Health Probe
| /shutdown | Shutdown the Spring Boot service | Managed Lifecycle
| /logs | Return the content of the logs | Stateful Service, Init Container |===
There is also a single class RandomRunner
included which creates a list of random numbers into a file:
./mvnw -pl spring compile
java -cp target/classes RandomRunner /tmp/random_numbers.txt 100000
This command is used in the Batch Job and Periodic Job pattern example. The last example is used in Daemon Service pattern example.
Refer to the Image Builder pattern how this example is build from within a Kubernetes cluster.
For creating a tag 2.0
just use the profile -Pv2
. This is used for creating images to be used the Declarative Deployment pattern.
In order to compile the images for multiple architectures, use: