<p>I am using Spring Cloud Kubernetes and I am trying to make feign able to send requests based on the name of the services present in kubernetes, but I can't, when I try to make a request the following error occurs:</p>

<pre><code>  "timestamp": "2019-12-06T15:37:50.285+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "com.netflix.client.ClientException: Load balancer does not have available server for client: poc-saldo",
    "trace": "java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available server for client: poc-saldo\n\tat org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient.execute....
</code></pre>

<p>I tried to call other services within the cluster and the problem is the same for all of them, I did a test by going into the poc-deposit pod and doing a poc-balance curl and it works normally, so the problem is not with the poc-deposit service. balance or with kubernetes's service discovery apparently.</p>

<p>The project has a public profile at:</p>

<pre><code>https://gitlab.com/viniciusxyz/spring-kubernetes-feign
</code></pre>

<p>For those who want more direct information:</p>

<p>My main class is as follows:</p>

<pre><code>@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ServiceDiscoveryApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceDiscoveryApplication.class, args);
    }

}
</code></pre>

<p>My interface with feign is as follows:</p>

<pre><code>@FeignClient("poc-saldo")
public interface ProxyGenerico {

    @RequestMapping(method = RequestMethod.GET)
    String getHttpResponse();

}
</code></pre>

<p>I can list the services available in kubernetes within the application as follows:</p>

<pre><code>@RestController
public class RestTest {

    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    private ProxyGenerico proxyGenerico;

    @GetMapping("/services")
    public ResponseEntity&lt;?&gt; services()  {
        return new ResponseEntity&lt;Object&gt;(discoveryClient.getServices(), HttpStatus.OK);
    }

    @GetMapping("/pocsaldo")
    public ResponseEntity&lt;?&gt; gitlab()  {

        return new ResponseEntity&lt;Object&gt;(proxyGenerico.getHttpResponse(), HttpStatus.OK);
    }

}
</code></pre>

<p>And in this list I have several services among them the service I want to access called poc-balance, the return json looks like the following:</p>

<pre><code>[

    "poc-deposito",
    "poc-saldo",
    "sonarqube",
    "sql-server-sonar",
    "zookeeper",
    "gitlab"

]
</code></pre>

<p>To complement the list follow my dependencies:</p>

<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
    &lt;artifactId&gt;spring-cloud-starter-openfeign&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
    &lt;artifactId&gt;spring-cloud-starter-kubernetes&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
    &lt;artifactId&gt;spring-cloud-starter-kubernetes-ribbon&lt;/artifactId&gt;
&lt;/dependency&gt;
</code></pre>

<p>The discoveryClient.getInstances ("poc-saldo") command returns:</p>

<pre><code>[
    {
        "instanceId": "32a4db0d-0549-11ea-8850-e0d55ef66cf8",
        "serviceId": "poc-saldo",
        "secure": false,
        "metadata": {
            "helm.sh/chart": "spring-boot-app-0.1.23",
            "port.http": "8080",
            "app.kubernetes.io/managed-by": "Tiller",
            "app.kubernetes.io/name": "poc-saldo",
            "app.kubernetes.io/instance": "banco-digital-poc-saldo",
            "app.kubernetes.io/version": "1.0"
        },
        "port": 8080,
        "host": "10.42.0.60",
        "scheme": "http://",
        "uri": "http://10.42.0.60:8080"
    }
]
</code></pre>

<p>Can you think of where the problem might be?</p>

Vinicius Santos
<p>Long story short, <strong>Spring Cloud Feign works perfectly fine with Spring Cloud Kubernetes</strong> as of July 2021. I've moved a <em>Spring Cloud Feign</em> project from using <em>Spring Cloud Netflix</em> to <em>Spring Cloud Kubernetes</em> and no change in the Feign interfaces was required. I just removed the previous <em>Service Registry (Eureka)</em> dependency from my <code>build.gradle</code> file and added:</p>
<pre><code>implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-client-all'
</code></pre>
<p>The support for <em>Spring Cloud LoadBalancer</em> which is now used by <em>Spring Cloud Feign</em> was added to <em>Spring Cloud Kubernetes</em> and <em>Ribbon</em> was removed as of <strong>Spring Cloud 2020.0. (aka Ilford)</strong>, therefore there is no need to exclude it anymore.</p>
<p>Beyond that, the only change required in the whole codebase was annotating the Spring Boot application class with <code>@EnableDiscoveryClient</code> to enable K8s-native Service Discovery:</p>
<pre><code>@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class BookApplication {
</code></pre>
<p><em>Spring Cloud Feign</em> uses <em>Spring Cloud LoadBalancer</em> which when running on Kubernetes leverages <a href="https://docs.spring.io/spring-cloud-kubernetes/docs/current/reference/html/index.html#discoveryclient-for-kubernetes" rel="noreferrer">Discovery Client for Kubernetes</a> to check for service instances. As a result, it only chooses from instances that are up and running. <strong>The only requirement is to align the Kubernetes service name with</strong>  <code>spring.application.name</code> <strong>property</strong>. Just like that:</p>
<p><em>application.properties(yaml)</em>:</p>
<pre><code>spring.application.name=library-book-service
</code></pre>
<p>combined with the following Kubernetes configuration</p>
<p><em>kubectl get svc</em>:</p>
<pre><code>NAME                       TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)             AGE
library-book-service       ClusterIP   10.100.200.235   &lt;none&gt;        8080/TCP            5d21h
</code></pre>
