Leader election with Spring Boot Cloud: Duplicate bean kubernetesHealthIndicator

151 Views Asked by At

I'm trying to add leader election to a Spring Boot 3.2 service running on a local Kubernetes cluster. The manual advises to add the spring-cloud-kubernetes-fabric8-leader dependency, so now I have

implementation 'org.springframework.cloud:spring-cloud-kubernetes-fabric8-leader:3.1.0'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:4.1.0'
implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-client-config:3.1.0'

This is too much, since on startup I get the error

The bean 'kubernetesHealthIndicator', defined in class path resource [org/springframework/cloud/kubernetes/fabric8/Fabric8ActuatorConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/cloud/kubernetes/client/KubernetesClientActuatorConfiguration.class] and overriding is disabled.

Sure, both spring-cloud-kubernetes-fabric8-leader and spring-cloud-starter-kubernetes-client-config define this. I seem to need both dependencies - so what should I do? Btw: These are the only spring-cloud dependencies of the application.

1

There are 1 best solutions below

1
On BEST ANSWER

The problem seems to be that spring-cloud-starter-kubernetes-* and spring-cloud-kubernetes-fabric8-* are not really compatible (and this is not properly documented).

Changing the dependencies to

implementation 'org.springframework.cloud:spring-cloud-kubernetes-fabric8-leader:3.1.0'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:4.1.0'
implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-fabric8-config:3.1.0'

solved this for me.