Discovery / Registration only works when K8s pod already registered.

10/11/2018

Thanks for Spring Boot Admin!

I am using it with Spring Cloud Kubernetes, our k8s pods only get discovered when we start the Spring Boot Admin, after the service pods have been started.

It seems looking at InstanceDiscoveryListener, the discovery of clients, will happen based on events. Like ApplicationReadyEvent (When starting) and i.e. InstanceRegisteredEvent.

Is it correct to say, that Spring Boot Admin, will not try to discover periodically? If so how do I make sure an event is fired from the application to Spring boot admin picks it up and registers the instance?

Especially to make sure, that instanced are registered when they are started after spring boot admin, was started. (The order in which k8s pods are started is arbitrary/hard to control, something in general we don't want to do).

Thank You! Christophew

Version:

    springBootAdminVersion = '2.0.1'
    springCloudVersion = 'Finchley.RELEASE'
    springCloudK8s = '0.3.0.RELEASE' 
-- Christophe Bouhier
kubernetes
spring-boot-admin
spring-cloud

1 Answer

2/17/2019

Not sure if this is the best way to solve it but seems to work:

class TimedInstanceDiscoveryListener extends InstanceDiscoveryListener {

    private static final Logger log = LoggerFactory.getLogger(TimedInstanceDiscoveryListener.class);

    public TimedInstanceDiscoveryListener(DiscoveryClient discoveryClient, InstanceRegistry registry, InstanceRepository repository) {
        super(discoveryClient, registry, repository);
        log.info("Starting custom TimedInstanceDiscoveryListener");
    }

    @Scheduled(fixedRate = 5000)
    public void periodicDiscovery() {
        log.info("Discovering new pod / services");
        super.discover();
    }
}
@Bean
@ConfigurationProperties(prefix = "spring.boot.admin.discovery")
public InstanceDiscoveryListener instanceDiscoveryListener(ServiceInstanceConverter serviceInstanceConverter,
                                                           DiscoveryClient discoveryClient,
                                                           InstanceRegistry registry,
                                                           InstanceRepository repository) {

    InstanceDiscoveryListener listener = new TimedInstanceDiscoveryListener(discoveryClient, registry, repository);
    listener.setConverter(serviceInstanceConverter);
    return listener;
}
-- Patrick Bray
Source: StackOverflow