I am attempting to load properties from a K8s configmap into my Spring Boot service using Spring Cloud Kubernetes Fabric8, as described in the Spring Cloud docs here.
My configmap for my service looks like this:
apiVersion: v1
kind: ConfigMap
metadata:
name: foo-my-service
namespace: foo
labels:
helm.sh/chart: my-service-1.0.0-SNAPSHOT
app.kubernetes.io/name: my-service
app.kubernetes.io/instance: foo
app.kubernetes.io/version: "1.0.0-SNAPSHOT"
app.kubernetes.io/managed-by: Helm
data:
spring.datasource.url: jdbc:postgresql://foo-postgresql/mydb
And my Spring Boot application.yaml
looks like this:
spring:
application:
name: foo-my-service
cloud:
kubernetes:
secrets:
enable-api: true
I'm using Fabric8 to communicate with k8s. This dependency is brought in as org.springframework.cloud:spring-cloud-starter-kubernetes-fabric8-config:jar:3.0.1
in my Maven pom.
I'm using Spring Boot version 3.0.3 and Spring Cloud 2022.0.1.
What I expect to happen based on the Spring Cloud documentation is that my spring.datasource.url
property will be set from the value in the configmap.
What's actually happening is that the property is not detected, and the Spring Boot application fails to start when it tries to use the property to run a Flyway migration.
│ Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. │
│ Reason: Failed to determine suitable jdbc url │
If I downgrade my Spring Boot version to 2.x and Spring Cloud to the corresponding version, then this works (my application starts up and the spring.datasource.url
property is set to the value in the configmap).
How do I get this to work in Spring Boot 3?