Spring Cloud Kubernetes Loadbalancer gives pod ip address instead of service url when spring.cloud.kubernetes.loadbalancer.mode=SERVICE
See original GitHub issueProblem
I am trying to use Spring Boot with Spring Cloud Kubernetes to discovery services with the loadbalancer in SERVICE
mode. I have followed the documentation from https://docs.spring.io/spring-cloud-kubernetes/docs/current/reference/html/index.html where it says to set spring.cloud.kubernetes.loadbalancer.mode=SERVICE
and include the following dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-fabric8-loadbalancer</artifactId>
</dependency>
In my sample project I have created two identical applications, app a and app b, both of which use the loadbalancer dependency and have loadbalancer set to SERVICE
mode. After running my k8s.yaml
file this is the output:
The last line of app a and app b logs show the ip address of the pod where I would have expected it to be something like service-a.default.svc.cluster.local
as mentioned in the documentation. To get the address output I am calling
System.out.println(discoveryClient.getInstances("service-b").get(0).getUri().toString());
for app a and System.out.println(discoveryClient.getInstances("service-a").get(0).getUri().toString());
for app b.
Any guidance would be greatly appreciated.
Sample https://github.com/pearsonradu/spring-cloud-kubernetes-loadbalancer-service-example
Versions:
- Docker Desktop: 3.1.0
- Kubernetes: 1.19.3
- Spring Boot: 2.4.5
- Spring Cloud: 2020.0.2
Includes
- app a
- app b
- k8s configuration
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (5 by maintainers)
Using the
@Loadbalanced
annotation seemed to do the trick! The request is successful with the annotation present and when it is removed the request fails. EnablingSERVICE
mode points to the cluster address and switching toPOD
points to the IP address. Thank you for the clarification!Great, I appreciate the help. I will give that a shot and get back to you.