spring-bootkubernetesspring-cloud-gateway

Cannot find remote pod service - SERVICE_UNAVAILABLE


I created a test project with Spring Cloud gateway and Spring microservice which are using implementation 'org.springframework.cloud:spring-cloud-kubernetes-client-discovery':

https://github.com/rcbandit111/kubernetes_discovery_client_poc

I configured rotes into Spring Gateway file:

https://github.com/rcbandit111/kubernetes_discovery_client_poc/blob/main/gateway/src/main/resources/application.yml

Both services are deployed into Kubernetes but request is not forwarded:

2024-04-02 13:21:55.817 TRACE 1 --- [     parallel-1] o.s.c.g.filter.RouteToRequestUrlFilter   : RouteToRequestUrlFilter start
2024-04-02 13:21:55.886 TRACE 1 --- [     parallel-1] o.s.c.g.filter.GatewayMetricsFilter      : spring.cloud.gateway.requests tags: [tag(httpMethod=GET),tag(httpStatusCode=503),tag(outcome=SERVER_ERROR),tag(routeId=microservice_1),tag(routeUri=lb://microservice_1),tag(status=SERVICE_UNAVAILABLE)]
2024-04-02 13:22:42.084 TRACE 1 --- [     parallel-1] o.s.c.g.f.WeightCalculatorWebFilter      : Weights attr: {}
2024-04-02 13:22:42.089 TRACE 1 --- [     parallel-1] o.s.c.g.h.p.PathRoutePredicateFactory    : Pattern "/api/microservice_1/dashboard/users" matches against value "/api/microservice_1/dashboard/users"
2024-04-02 13:22:42.095 DEBUG 1 --- [     parallel-1] o.s.c.g.h.RoutePredicateHandlerMapping   : Route matched: microservice_1
2024-04-02 13:22:42.096 DEBUG 1 --- [     parallel-1] o.s.c.g.h.RoutePredicateHandlerMapping   : Mapping [Exchange: GET http://11.111.63.1:30057/api/microservice_1/dashboard/users?startDate=2024-03-02T14:21:45.540Z&endDate=2024-04-02T13:22:40.533Z] to Route{id='microservice_1', uri=lb://microservice_1, order=0, predicate=Paths: [/api/microservice_1/dashboard/users], match trailing slash: true, gatewayFilters=[[[RemoveRequestHeader name = 'Cookie'], order = 1], [[SpringCloudCircuitBreakerResilience4JFilterFactory name = 'microservice_1', fallback = [null]], order = 2], [[RewritePath /api/dashboard/users = '/dashboard/users'], order = 3]], metadata={}}
2024-04-02 13:22:42.096 DEBUG 1 --- [     parallel-1] o.s.c.g.h.RoutePredicateHandlerMapping   : [9b4aa35e-33] Mapped to org.springframework.cloud.gateway.handler.FilteringWebHandler@20a20ac5
2024-04-02 13:22:42.097 DEBUG 1 --- [     parallel-1] o.s.c.g.handler.FilteringWebHandler      : Sorted gatewayFilterFactories: [[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RemoveCachedBodyFilter@39c1fe0b}, order = -2147483648], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@b016b4e}, order = -2147482648], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@3e5d4f6b}, order = -1], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardPathFilter@367b22e5}, order = 0], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.GatewayMetricsFilter@10bd9df0}, order = 0], [[RemoveRequestHeader name = 'Cookie'], order = 1], [[SpringCloudCircuitBreakerResilience4JFilterFactory name = 'microservice_1', fallback = [null]], order = 2], [[RewritePath /api/dashboard/users = '/dashboard/users'], order = 3], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@5ae95707}, order = 10000], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.config.GatewayNoLoadBalancerClientAutoConfiguration$NoLoadBalancerClientFilter@3ae0b770}, order = 10150], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@fca387}, order = 2147483646], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyRoutingFilter@1ac45389}, order = 2147483647], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardRoutingFilter@62891fc8}, order = 2147483647]]

I suspect that microservice name is not resolved. Any idea what might be wrong?


Solution

  • Solution:

    Update and use latest Spring Boot 3.x.x with implementation 'org.springframework.cloud:spring-cloud-kubernetes-client-discovery:3.1.1'