Spring Cloud Kubernetes FeignClient Error

3/8/2019

I am using spring cloud kubernetes with spring boot and necessary RBAC requirements needed for the project.

<!-- kubernetes -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-kubernetes</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-kubernetes-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId>
        </dependency>

I have 2 microservices running in kubernetes

  1. my-service
  2. some-service

The my-service is running with spring boot 2.x and some-service is running with Spring boot 1.x. Both the services are exposed via the Kubernetes Service and with proper endpoints.

excerpt of application.yaml for my-service is as below.

some-service:
      url: http://some-service:8080
      serviceName: some-service

And the FeignClient used is as below.

//FeignClient(url = "${some-service.url}") // does not work either
@FeignClient(value = "${some-service.serviceName}")
@RequestMapping("/api")
public interface SomeServiceClient {

Also I have made spring.cloud.kubernetes.discovery.enabled=false

With this in place I expect that my-service should be able to talk to some-service via kubernetes service discovery But I get this error.

ERROR c.b.d.m.s.c.MatchCoordinator - error=FeignException: status 404 reading SomeServiceClient#get(Test
ion,Output) stacktrace=feign.FeignException: status 404 reading SomeServiceClient#get

I am unable to understand what am I doing wrong. Also I do not have the spring.application.name set for some-service since its a third party service.

Can someone please help. Also FYI that the services work properly with port-forwarding and if accessed via Ingress.

-- chaosguru
kubernetes
spring
spring-boot
spring-cloud-feign
spring-cloud-kubernetes

2 Answers

3/12/2019

Well, I found that the discrepancy was at the some-service where the payload of was updated and my-service FeignClient was not updated. and hence caused the HTTP 404 Error. However it works now with the FeignClient properly and able to do a service discovery with the service name properly.

-- chaosguru
Source: StackOverflow

3/8/2019

If you do not have a name set for some-service, and it's a 3rd party service, I think the better approach would be to call it via RestTemplate or something.

Feign client needs to have the service name configured and known, for it to call that particular service in the network using service discovery.

-- Muhammad Inshal
Source: StackOverflow