In kubernetes (k8s) we can monitor our spring boot services and gain insights on it with Prometheus and Grafana.
Continuing on from our previous post, Spring Data REST on Kubernetes. We add the following dependency to the vadal-data-rest service pom.xml.
<!-- Micrometer Prometheus registry -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
Build and Deploy the image to k8s
mvn spring-boot:build-image
there should be an update to the docker image
docker images
vadal-data-rest 0.0.1-SNAPSHOT
Tell k8s to update the image in the pod:
kubectl patch deploy vadal-data-rest -p ‘{“spec”:{“template”:{“spec”:{“terminationGracePeriodSeconds”:29}}}}’
Delete any older installation.
helm del — purge prometheus
Install it.
helm install — wait — name prometheus — set service.type=NodePort,service.nodePort=9090 stable/prometheus
Note the local cluster url, prometheus-server.default.svc.cluster.local, we will need this to connect grafana to it.
Make it available on port 30001
kubectl edit svc/prometheus-server
and change the nodePort to 30001
#grafana #prometheus #spring-boot #spring