You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary
When building a Docker image with the native profile enabled using the spring-boot-maven-plugin, the application fails to start with a KubernetesClientException error due to a ClassNotFoundException for io.fabric8.kubernetes.client.impl.KubernetesClientImpl. The issue does not occur without the -Pnative profile.
Spring boot version 3.4.1
Spring cloud 3.2.0
Steps to Reproduce
Use the provided spring-boot-maven-plugin configuration.
Execute the Maven command: mvn -Pnative spring-boot:build-image -Dmaven.test.skip=true -Ddocker.publishRegistry.url=xx -Ddocker.publishRegistry.token=xx
Run the generated Docker image.
Plugin Configuration
Here is the relevant part of the Maven configuration for the spring-boot-maven-plugin:
Expected Behavior
The application should start successfully within the Docker container.
Actual Behavior
The application fails to start, and the following error is observed in the logs:
Application run failed
2025-01-09T08:23:54.867245501Z io.fabric8.kubernetes.client.KubernetesClientException: An error has occurred.
2025-01-09T08:23:54.867255250Z at io.fabric8.kubernetes.client.KubernetesClientBuilder.(KubernetesClientBuilder.java:61)
2025-01-09T08:23:54.867262772Z at org.springframework.cloud.kubernetes.fabric8.profile.Fabric8ProfileEnvironmentPostProcessor.isInsideKubernetes(Fabric8ProfileEnvironmentPostProcessor.java:31)
2025-01-09T08:23:54.867268992Z at org.springframework.cloud.kubernetes.commons.profile.AbstractKubernetesProfileEnvironmentPostProcessor.addKubernetesProfileIfMissing(AbstractKubernetesProfileEnvironmentPostProcessor.java:80)
at org.springframework.cloud.kubernetes.commons.profile.AbstractKubernetesProfileEnvironmentPostProcessor.postProcessEnvironment(AbstractKubernetesProfileEnvironmentPostProcessor.java:64)
2025-01-09T08:23:54.867283021Z at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:132)
2025-01-09T08:23:54.867289214Z at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:115)
2025-01-09T08:23:54.867294841Z at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
2025-01-09T08:23:54.867300507Z at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
2025-01-09T08:23:54.867306124Z at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
2025-01-09T08:23:54.867311765Z at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
2025-01-09T08:23:54.867317343Z at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
2025-01-09T08:23:54.867328694Z at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
2025-01-09T08:23:54.867335164Z at [email protected]/java.lang.Iterable.forEach(Iterable.java:75)
2025-01-09T08:23:54.867342365Z at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
2025-01-09T08:23:54.867353772Z at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
2025-01-09T08:23:54.867359371Z at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:353)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
2025-01-09T08:23:54.867379620Z at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149)
2025-01-09T08:23:54.867386029Z at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:198)
2025-01-09T08:23:54.867392158Z at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114)
2025-01-09T08:23:54.867397885Z at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77)
2025-01-09T08:23:54.867403507Z at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
2025-01-09T08:23:54.867409248Z at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
2025-01-09T08:23:54.867414907Z at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
2025-01-09T08:23:54.867423830Z at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
2025-01-09T08:23:54.867433202Z at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
2025-01-09T08:23:54.867442097Z at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
2025-01-09T08:23:54.867451178Z at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
2025-01-09T08:23:54.867460325Z at [email protected]/java.lang.Iterable.forEach(Iterable.java:75)
2025-01-09T08:23:54.867469963Z at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(
SpringApplicationRunListeners.java:118)
2025-01-09T08:23:54.867479587Z at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
2025-01-09T08:23:54.867486193Z at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
2025-01-09T08:23:54.867491790Z at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:353)
2025-01-09T08:23:54.867497216Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
2025-01-09T08:23:54.867502704Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
2025-01-09T08:23:54.867508430Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
2025-01-09T08:23:54.867521830Z at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
2025-01-09T08:23:54.867530778Z Caused by: java.lang.ClassNotFoundException: io.fabric8.kubernetes.client.impl.KubernetesClientImpl
2025-01-09T08:23:54.867549647Z at [email protected]/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:52)
2025-01-09T08:23:54.867558293Z at [email protected]/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
2025-01-09T08:23:54.867564025Z at [email protected]/java.lang.ClassLoader.loadClass(ClassLoader.java:121)
2025-01-09T08:23:54.867569680Z at io.fabric8.kubernetes.client.KubernetesClientBuilder.(KubernetesClientBuilder.java:59)
2025-01-09T08:23:54.867575980Z ... 39 more
Workaround
Running the application without the native profile works as expected.
If you want support, please take the time to share an actual sample the team can run, your pom is not an actionable sample. You can attach the sample as a zip here or you can push the code to a GitHub repository and share the link.
Also, the docker image is ready to pull it ghcr.io/alidandach/spring-cloud-k8s-bug:1.0
The problem is when I build the image using spring native profile "-Pnative" and run it under Kubernetes with flag "SPRING_CLOUD_BOOTSTRAP_ENABLED=true" I got that error. Same code, without "-Pnative" works as expected. Can you advise about that error please?
Summary
When building a Docker image with the native profile enabled using the spring-boot-maven-plugin, the application fails to start with a KubernetesClientException error due to a ClassNotFoundException for io.fabric8.kubernetes.client.impl.KubernetesClientImpl. The issue does not occur without the -Pnative profile.
Spring boot version 3.4.1
Spring cloud 3.2.0
Steps to Reproduce
mvn -Pnative spring-boot:build-image -Dmaven.test.skip=true -Ddocker.publishRegistry.url=xx -Ddocker.publishRegistry.token=xx
Plugin Configuration
Here is the relevant part of the Maven configuration for the spring-boot-maven-plugin:
Here is the pom.xml
pom.zip
Expected Behavior
The application should start successfully within the Docker container.
Actual Behavior
The application fails to start, and the following error is observed in the logs:
Application run failed
2025-01-09T08:23:54.867245501Z io.fabric8.kubernetes.client.KubernetesClientException: An error has occurred.
2025-01-09T08:23:54.867255250Z at io.fabric8.kubernetes.client.KubernetesClientBuilder.(KubernetesClientBuilder.java:61)
2025-01-09T08:23:54.867262772Z at org.springframework.cloud.kubernetes.fabric8.profile.Fabric8ProfileEnvironmentPostProcessor.isInsideKubernetes(Fabric8ProfileEnvironmentPostProcessor.java:31)
2025-01-09T08:23:54.867268992Z at org.springframework.cloud.kubernetes.commons.profile.AbstractKubernetesProfileEnvironmentPostProcessor.addKubernetesProfileIfMissing(AbstractKubernetesProfileEnvironmentPostProcessor.java:80)
at org.springframework.cloud.kubernetes.commons.profile.AbstractKubernetesProfileEnvironmentPostProcessor.postProcessEnvironment(AbstractKubernetesProfileEnvironmentPostProcessor.java:64)
2025-01-09T08:23:54.867283021Z at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:132)
2025-01-09T08:23:54.867289214Z at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:115)
2025-01-09T08:23:54.867294841Z at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
2025-01-09T08:23:54.867300507Z at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
2025-01-09T08:23:54.867306124Z at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
2025-01-09T08:23:54.867311765Z at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
2025-01-09T08:23:54.867317343Z at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
2025-01-09T08:23:54.867328694Z at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
2025-01-09T08:23:54.867335164Z at [email protected]/java.lang.Iterable.forEach(Iterable.java:75)
2025-01-09T08:23:54.867342365Z at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
2025-01-09T08:23:54.867353772Z at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
2025-01-09T08:23:54.867359371Z at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:353)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
2025-01-09T08:23:54.867379620Z at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149)
2025-01-09T08:23:54.867386029Z at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:198)
2025-01-09T08:23:54.867392158Z at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114)
2025-01-09T08:23:54.867397885Z at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77)
2025-01-09T08:23:54.867403507Z at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
2025-01-09T08:23:54.867409248Z at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
2025-01-09T08:23:54.867414907Z at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
2025-01-09T08:23:54.867423830Z at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
2025-01-09T08:23:54.867433202Z at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
2025-01-09T08:23:54.867442097Z at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
2025-01-09T08:23:54.867451178Z at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
2025-01-09T08:23:54.867460325Z at [email protected]/java.lang.Iterable.forEach(Iterable.java:75)
2025-01-09T08:23:54.867469963Z at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(
SpringApplicationRunListeners.java:118)
2025-01-09T08:23:54.867479587Z at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
2025-01-09T08:23:54.867486193Z at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
2025-01-09T08:23:54.867491790Z at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:353)
2025-01-09T08:23:54.867497216Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
2025-01-09T08:23:54.867502704Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
2025-01-09T08:23:54.867508430Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
2025-01-09T08:23:54.867521830Z at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
2025-01-09T08:23:54.867530778Z Caused by: java.lang.ClassNotFoundException: io.fabric8.kubernetes.client.impl.KubernetesClientImpl
2025-01-09T08:23:54.867549647Z at [email protected]/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:52)
2025-01-09T08:23:54.867558293Z at [email protected]/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
2025-01-09T08:23:54.867564025Z at [email protected]/java.lang.ClassLoader.loadClass(ClassLoader.java:121)
2025-01-09T08:23:54.867569680Z at io.fabric8.kubernetes.client.KubernetesClientBuilder.(KubernetesClientBuilder.java:59)
2025-01-09T08:23:54.867575980Z ... 39 more
Workaround
Running the application without the native profile works as expected.
Already reported in Spring Framework but it seems not in the correct place:
spring-projects/spring-framework#34218
The text was updated successfully, but these errors were encountered: