Spring Cloud Kubernetes,网关路由映射

问题描述

我正在学习 Spring boot kubernetes 并尝试为我的服务设置 spring 云网关。我相信使用 Spring 云网关,我们不必再使用功能区进行负载平衡。所以如果我不使用功能区,那么路由的配置也会发生变化。我查看了网站以寻求建议,以下是我发现的内容:-

routes:
- id: department_route
  uri: http://departmentservice:4200 # 
  predicates:
  - Path=/* 

在这种情况下,uri 具有可用服务的硬编码端口值。这是推荐的方法吗?

然后还有另一种配置,看起来像这样,不确定 url-expression 试图做什么 :-

spring:
  application.name: gateway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          url-expression: "'http://'+serviceId"
  server.port: 8080

是否不能按名称进行服务发现并在其后附加谓词?

解决方法

我仍在修复主要的 Spring Cloud Gateway 项目,但以下对我有用。我已经通过 Zuul 配置了路由,因此请确保您的依赖项和与之相关的配置匹配:-

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-kubernetes-all</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>

**Config :: application.yaml ::**

    zuul:
      routes:
        shopping-cart-service:
          path: "/shopping-cart-service/**"
        item-service:
          path: "/item-service/**"