Search code examples
javaspring-bootspring-boot-admin

Monitoring replicas with Spring Boot Admin on Kubernetes


I setted up a Spring Boot Admin Client on Kubernetes and scaled up to 3 replicas, but when I try to check the instances the Admin Server show just one


Solution

  • In order for SBA (Spring Boot Admin) to understand that the three instances of your services are distinct, you need to make sure each is registered in SBA using its "internal IP address".

    Doing so will let SBA query the health of each instance independently, and will result with spring creating unique instance-id for each pod.

    Note that using the k8s service name for the registration will result with SBA's health queries being load-balanced across the service's pods.

    To do this, add to your application.yml the following:

    spring:
      boot.admin.client:
        url: http://<k8s-service-name-and-port>
        instance:
          name: <service-name>
          service-base-url: http://${K8S_POD_IP}:8080
          management-base-url: http://${K8S_POD_IP}:8081
        auto-deregistration: true
    

    Having:

    • K8S_POD_IP is an environment-variable with the pod's IP address that must be accessible from SBA - this is the address that will be used by SBA to query for your service instance's health
    • spring.boot.admin.client.url is the URL that will be used by SBA's UI when you click on an instance of your service - this URL should point to k8s's service
    • spring.boot.admin.client.management-base-url - this is used by SBA to monitor every service's health, should be unique for every instance and should be accessible from SBA
    • If you don't set auto-deregistration to true whenever you roll out an update or scale down your service, you'll get notification of unhealthy instances - with this setting, instances will derigister from SBA when shutdown.