This repository is a fork of Spring Music, a famous Spring Boot demo application, together with a charmed operator that enables Juju to run the application on top of Kubernetes.
The Spring Music charm operators integrates with other charmed operators, specifically:
prometheus_scrape
relation interface, like Grafana Agent;These instructions are tailored to an Ubuntu 20.04 or later environment, although snap
supports tons of different Linux distributions.
Install MicroK8s with the following add ons: storage
, dns
, registry
:
snap install microk8s
microk8s enable storage dns registry
snap install juju
snap install charmcraft
The charmcraft pack
command relies on LXD to build charms in a safe and reproducible way.
Install LXD on your machine as follows:
snap install lxd
lxd init --minimal
juju bootstrap microk8s development
Assuming you are using MicroK8s with the registry
add on, build the OCI image of the Spring Music application with:
./gradlew bootBuildImage --imageName=localhost:32000/spring-music:latest
docker build . -f Dockerfile.local -t localhost:32000/spring-music:latest
docker push localhost:32000/spring-music:latest
The localhost:32000
is the location of the registry integrated in MicroK8s.
The docker build . -f Dockerfile.local ...
command removes from the Docker image built by Gradle a number of overly large image labels that are known to cause issues with containerd runtimes.
charmcraft pack
juju add-model spring
juju deploy ./spring-music_ubuntu-20.04-amd64.charm spring-music --resource application-image=localhost:32000/spring-music
Alternatively, the ./build_and_deploy_charm
automates the build and deploy (or refresh) of the charm in a model:
./juju_utils/build_and_deploy_charm spring spring-music
Follow the LMA Light on MicroK8s tutorial together with the offers overlay.
juju switch spring
juju consume lma.prometheus-scrape prometheus
juju consume lma.grafana-dashboards grafana
juju consume lma.loki-logging loki
juju add-relation spring-music prometheus
juju add-relation spring-music grafana
juju add-relation spring-music loki
In the ./juju_utils/
folder there are three utility scripts to streamline some common development tasks:
The ./juju_utils/build_and_deploy_charm
bash script automates the creation of the charm (i.e., charmcraft pack
) and its deployment or the update of the application; it accepts two additional, optional arguments, the first for the model in which to deploy, and the second the application name:
./juju_utils/build_and_deploy_charm <model> <application>
The default model is spring
, and the default application name is spring-music
Important: The ./juju_utils/build_and_deploy_charm
bash script does not build the OCI image for the Spring Music application, nor it uploads it to the local MicroK8s registry.
Refer to the Building the Spring Music container image for instructions on how to ensure that the OCI image for the Spring Music application is available in the local MicroK8s registry.
The ./juju_utils/juju-unit-address
bash script outputs the address and port of the provided Juju unit:
./juju_utils/juju-unit-address <model>.<application>/<unit_id>
For example:
$ ./juju_utils/juju-unit-address lma.prometheus/0
10.1.151.75:9090
The ./juju_utils/browse-juju-unit
bash script opens the address and port of the provided Juju unit in Firefox:
./juju_utils/browse-juju-unit <model>.<application>/<unit_id>
For example:
./juju_utils/browse-juju-unit lma.prometheus/0
would result in Firefox opening something like the 10.1.151.75:9090
address.
To play nice with Maven and Gradle, the charm code is located in directories that different than in "normal" charm repository (e.g., what charmcraft init
sets up for you):
src/main/charm
metadata.yaml
in src/main/charm_resources
src/main/charm_libs
src/test/charm
Achieving the above required the following adjustments:
charm-entrypoint
in charmcraft.yaml
dispatch
script to ensure that the charm libraries are visible in the Charm containertox.ini
src/main/charm_resources/metadata.yaml
to metadata.yaml
for charmcraft pack
's benefitlib/charms
to src/main/charm_libs
for charmcraft fetch-lib
's benefit