spring.cloud.kubernetes.discovery-server-url must be specified and a valid URL

Viewed 326

I'm updating a service's dependencies from Spring Boot 2.3.12.RELEASE to 2.7.0 and Spring Cloud from Hoxton.Release to 2021.0.3

Upon doing this, I'm starting to get kubernetes errors that I didn't see with the previous dependency versions.

nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'compositeDiscoveryClient' defined in class path resource [org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClientAutoConfiguration.class]: Unsatisfied dependency expressed through method 'compositeDiscoveryClient' parameter 0; 

nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kubernetesDiscoveryClient' defined in class path resource [org/springframework/cloud/kubernetes/discovery/KubernetesDiscoveryClientAutoConfiguration$Servlet.class]: Bean instantiation via factory method failed; 

nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.client.discovery.DiscoveryClient]: Factory method 'kubernetesDiscoveryClient' threw exception; 

nested exception is org.springframework.cloud.kubernetes.discovery.DiscoveryServerUrlInvalidException: spring.cloud.kubernetes.discovery-server-url must be specified and a valid URL.

I've read a few tutorials about using the @EnableDiscoveryClient annotation in the application as well as autowiring the DiscoveryClient in the controllers, including the Baeldung tutorial. However, I have yet to see anything mention a discovery-server-url.

Where do I set this value, or how to I tell Spring and Kubernetes what to look for?

1 Answers

Notice that "spring.cloud.kubernetes.discovery-server-url" has a spelling error in Springs error message. The parameter name is spring.cloud.kubernetes.discovery.discovery-server-url.

It can be set anywhere in Springs external configuration (.properties, .yaml). Regarding K8s, the quickest way is perhaps the args in your deployment.yaml:

  template:
    metadata:
      labels:
        ...
    spec:
      containers:
      - name: ...
        image: ...
        command: ["java"]
        args: ["-Dspring.profiles.active=kubernetes", "-Dspring.cloud.kubernetes.discovery.discovery-server-url=http://spring-cloud-kubernetes-discoveryserver.default.svc.cluster.local", "-Dspring.cloud.kubernetes.discovery.enabled=true", "org.springframework.boot.loader.JarLauncher"]
        ports:
            ...
Related