- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Description
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.
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:
	<build>
		<finalName>${project.artifactId}</finalName>
		<plugins>
			<!--spring boot launcher-->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<image>
						<publish>true</publish>
						<name>${docker.publishRegistry.url}</name>
						<env>
							<BP_JVM_VERSION>21</BP_JVM_VERSION>
							<BP_JVM_CDS_ENABLED>true</BP_JVM_CDS_ENABLED>
							<BPL_JVM_CDS_ENABLED>true</BPL_JVM_CDS_ENABLED>
							<BP_SPRING_AOT_ENABLED>true</BP_SPRING_AOT_ENABLED>
							<BPL_SPRING_AOT_ENABLED>true</BPL_SPRING_AOT_ENABLED>
							<BP_SPRING_CLOUD_BINDINGS_VERSION>2</BP_SPRING_CLOUD_BINDINGS_VERSION>
							<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>-H:+AddAllCharsets --enable-https</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
						</env>
					</image>
					<docker>
						<publishRegistry>
							<username>docker_registry_push_pull</username>
							<password>${docker.publishRegistry.token}</password>
						</publishRegistry>
					</docker>
				</configuration>
			</plugin>
			<!--graalvm build tools-->
			<plugin>
				<groupId>org.graalvm.buildtools</groupId>
				<artifactId>native-maven-plugin</artifactId>
			</plugin>
					</plugins>
	</build>
Maven dependencies :
		<!--spring cloud kubernetes fabric8-->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-kubernetes-fabric8</artifactId>
			<version>${spring-cloud-kubernetes-fabric8.version}</version>
		</dependency>
		<!--spring cloud kubernetes client-->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-kubernetes-client</artifactId>
			<version>${spring-cloud-kubernetes-fabric8.version}</version>
		</dependency>
		<!--spring cloud kubernetes config-->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-kubernetes-fabric8-config</artifactId>
			<version>${spring-cloud-kubernetes-fabric8.version}</version>
		</dependency>
		<!--spring cloud kubernetes client config-->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-kubernetes-client-config</artifactId>
			<version>${spring-cloud-kubernetes-fabric8.version}</version>
		</dependency>
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.