Spring Cloud Kubernetes app failed to start:

170 views Asked by At

I have an simple app with spring boot EKS with kubernetes JDK17 spring-boot-starter-parent 3.1.3 spring-cloud-dependencies spring-cloud-starter-kubernetes-fabric8-config spring-cloud-starter-bootstrap

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 2 of method configMapPropertyChangeEventWatcher in org.springframework.cloud.kubernetes.fabric8.config.reload.Fabric8ConfigReloadAutoConfiguration required a single bean,
 but 2 were found:
    - configDataConfigMapPropertySourceLocator: a programmatically registered singleton 
    - configMapPropertySourceLocator: defined by method 'configMapPropertySourceLocator' 
    in class path resource [org/springframework/cloud/kubernetes/fabric8/config/Fabric8BootstrapConfiguration.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
","context":"default"}

bootstrap.properties:

spring.cloud.bootstrap.enabled=true
spring.main.cloud-platform=KUBERNETES
spring.cloud.kubernetes.discovery.enabled=false
spring.cloud.kubernetes.config.enabled=true
spring.cloud.kubernetes.reload.enabled=true
spring.cloud.kubernetes.secrets.enabled=true
spring.cloud.kubernetes.reload.monitoring-secrets=true

application.properties

spring.application.name=demo
spring.main.allow-bean-definition-overriding=true
spring.cloud.bootstrap.enabled=true
spring.main.cloud-platform=KUBERNETES

Does anyone have any ideas about what I am missing ?

2

There are 2 answers

0
Eugene On

spring-cloud-kubernetes contributor here.

You are using both config data api and bootstrap, at the same time, so 2 beans are created, where one is expected.

What I mean by that is that you have: spring.config.import:kubernetes in application.properties (this is called "config data api" and is a modern replacement of "bootstrap", see this for more details)

At the same time, you have enabled bootstrap also: you either have spring-cloud-starter-bootstrap on the classpath or this is set: spring.cloud.bootstrap.enabled=true.

Since both of these are configured, each will create a @Bean, but we expect only one. So disable one of them.

1
Alberto San José On

It was not as straightforward in my case as @Eugene suggested, unless I am still missing something.

I had the bootstrap.properties file removed from my application and replaced by an application.properties file, following the so called "config data API", and then I ended in the problem described here, which I also reported in Spring application fails to start because Fabric8ConfigReloadAutoConfiguration required a single bean but 2 were found.

Then I issued the question above and I ended up in this one. Following @Eugene suggestion, I realized that a pom used in my project to manage dependencies was including spring-cloud-starter-bootstrap, so I excluded it from my application. And then I have a new problem:

Parameter 0 of method kubernetesHealthIndicator in 
org.springframework.cloud.kubernetes.fabric8.Fabric8ActuatorConfiguration
required a bean of type 'org.springframework.cloud.kubernetes.commons.PodUtils'
that could not be found.


Action:

Consider defining a bean of type 'org.springframework.cloud.kubernetes.commons.PodUtils'
in your configuration

Of course, I have checked that I do not have bootstrap activated by any other property. So it seems I cannot get rid so easily of spring-cloud-starter-bootstrap. I will edit this answer in case I make new findings and they can be of any help.