question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring Cloud Kubernetes Loadbalancer gives pod ip address instead of service url when spring.cloud.kubernetes.loadbalancer.mode=SERVICE

See original GitHub issue

Problem 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:

image

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:closed
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pearsonraducommented, May 27, 2021

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. Enabling SERVICE mode points to the cluster address and switching to POD points to the IP address. Thank you for the clarification!

1reaction
pearsonraducommented, May 26, 2021

Great, I appreciate the help. I will give that a shot and get back to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Cloud Kubernetes
This reference guide covers how to use Spring Cloud Kubernetes. ... addresses and that a client can access from a Spring Boot application...
Read more >
Spring Cloud Kubernetes Load Balancer Guide
It provides two modes of communication. First of them detects IP addresses of all pods running within a given service. The second of...
Read more >
Load balancing problems with Spring Cloud Kubernetes
We have a problem that when one of the target pods goes down we get multiple failures for requests for a period of...
Read more >
K8S(kubernetes) - Spring Cloud
Spring Cloud Kubernetes provides an implementation of the well-known ... setting load balancer server list with ip of pod * or service name....
Read more >
Guide to Spring Cloud Kubernetes - Baeldung
In particular, the Kubernetes health indicator provides: pod name; IP address; namespace; service account; node name; a flag that indicates ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found