spring-cloud-kubernetes: Cloud Gateway with Kubernetes not working

I am trying to move from Zuul to Gateway after TokenRelayGatewayFilterFactory is released . I did the static route as below

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("common", r -> r.path("/common/**")
                        .filters(f -> f.stripPrefix(1).filter(filterFactory.apply()))
                        .uri("http://10.100.135.181:8083"))
                .build();
    }

and it worked perfectly , but when trying to use the DiscoveryClient from kubernetes it is not working .

All services are being discovered , i can see that in the log but restTemplate is not trying to get the endpoint IP instead it is keeping the service name . I tried to set the url-expression to http://'+serviceId , but started getting hostname not found and with lb://service-id i am getting just 200 OK without any try to the service

2019-02-04 12:37:38.384 TRACE 16483 --- [ctor-http-nio-2] o.s.c.g.h.p.RoutePredicateFactory        : Pattern "/common/**" matches against value "/common/"
2019-02-04 12:37:38.384 DEBUG 16483 --- [ctor-http-nio-2] o.s.c.g.h.RoutePredicateHandlerMapping   : Route matched: CompositeDiscoveryClient_common
2019-02-04 12:37:38.384 DEBUG 16483 --- [ctor-http-nio-2] o.s.c.g.h.RoutePredicateHandlerMapping   : Mapping [Exchange: GET http://localhost:8080/common/] to Route{id='CompositeDiscoveryClient_common', uri=lb://common, order=0, predicate=org.springframework.cloud.gateway.support.ServerWebExchangeUtils$$Lambda$1027/166851221@19fa15e4, gatewayFilters=[OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactory$$Lambda$1029/275745728@8d968c9, order=1}]}
2019-02-04 12:37:38.384 DEBUG 16483 --- [ctor-http-nio-2] o.s.c.g.h.RoutePredicateHandlerMapping   : [dd19dc7c] Mapped to org.springframework.cloud.gateway.handler.FilteringWebHandler@784f9602
2019-02-04 12:37:38.385 DEBUG 16483 --- [ctor-http-nio-2] o.s.c.g.handler.FilteringWebHandler      : Sorted gatewayFilterFactories: [OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@660b1a9d}, order=-2147482648}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.GatewayMetricsFilter@7f426ddd}, order=-2147473648}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@587f4f63}, order=-1}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardPathFilter@2f4d01b6}, order=0}, OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactory$$Lambda$1029/275745728@8d968c9, order=1}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@6fb0261e}, order=10000}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@112c2930}, order=2147483646}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyRoutingFilter@6d31f106}, order=2147483647}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardRoutingFilter@d6b532f}, order=2147483647}]
2019-02-04 12:37:38.391 TRACE 16483 --- [ctor-http-nio-2] o.s.c.g.filter.RouteToRequestUrlFilter   : RouteToRequestUrlFilter start
2019-02-04 12:37:38.398 TRACE 16483 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter    : [dd19dc7c] Completed 200 OK, headers={masked}
2019-02-04 12:37:38.401 TRACE 16483 --- [ctor-http-nio-2] o.s.c.g.filter.GatewayMetricsFilter      : Stopping timer 'gateway.requests' with tags [tag(outcome=SUCCESSFUL),tag(routeId=CompositeDiscoveryClient_common),tag(routeUri=lb://common),tag(status=OK)]
2019-02-04 12:37:38.401 TRACE 16483 --- [ctor-http-nio-2] org.springframework.web.HttpLogging      : [dd19dc7c] Handling completed

A sample of the gateway is found here https://github.com/shahbour/gateway-demo

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 27 (27 by maintainers)

Most upvoted comments

No that is the point of using the starter. You will not be adding spring-cloud-kubernetes-ribbon to your classpath you will be adding the starter.

hello @ryanjbaxter , I did test the gateway and it is working. I was missing the Netflix ribbon dependency adding kubernetes ribbon is not enough.

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

Now Gateway is looking for endpoints for the service i am trying to access .

Note : I did test it from IDE and it just worked

is spring-cloud-kubernetes-ribbon on the classpath?