Kubernetes服务发现中的Spring云网关配置问题
我正在尝试将SpringCloudGateway与kubernetes服务发现一起使用。下面是我正在使用的设置 build.gradleKubernetes服务发现中的Spring云网关配置问题,kubernetes,spring-cloud,spring-cloud-gateway,Kubernetes,Spring Cloud,Spring Cloud Gateway,我正在尝试将SpringCloudGateway与kubernetes服务发现一起使用。下面是我正在使用的设置 build.gradle plugins { id 'org.springframework.boot' version '2.2.0.BUILD-SNAPSHOT' id 'io.spring.dependency-management' version '1.0.8.RELEASE' id 'java' } group = 'com.example' ve
plugins {
id 'org.springframework.boot' version '2.2.0.BUILD-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
ext {
set('springCloudVersion', "Hoxton.BUILD-SNAPSHOT")
set('springCloudKubernetesVersion', "1.0.3.RELEASE")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes'
implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-ribbon'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.springframework.cloud:spring-cloud-kubernetes-dependencies:${springCloudKubernetesVersion}"
}
}
test {
useJUnitPlatform()
}
application.yml
spring:
application.name: gateway
cloud:
gateway:
discovery:
locator:
enabled: true
kubernetes:
reload:
enabled: true
server:
port: 8080
logging:
level:
org.springframework.cloud.gateway: TRACE
org.springframework.cloud.loadbalancer: TRACE
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
enabled: true
info:
enabled: true
DemoApplication.java
package com.example.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class DemoApplication {
@Autowired
private DiscoveryClient discoveryClient;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/services")
public List<String> services() {
return this.discoveryClient.getServices();
}
}
package com.example.gateway;
导入org.springframework.boot.SpringApplication;
导入org.springframework.boot.autoconfigure.springboot应用程序;
导入org.springframework.cloud.client.discovery.EnableDiscoveryClient;
导入org.springframework.web.bind.annotation.RestController;
导入org.springframework.cloud.client.DiscoveryClient;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.web.bind.annotation.GetMapping;
导入java.util.List;
@SpringBoot应用程序
@EnableDiscoveryClient
@RestController
公共类演示应用程序{
@自动连线
私人发现客户发现客户;
公共静态void main(字符串[]args){
run(DemoApplication.class,args);
}
@GetMapping(“/services”)
公共列表服务(){
返回这个.discoveryClient.getServices();
}
}
Spring云网关无法将请求重定向到其他服务。正在打印的日志是
2019-10-13 18:29:38.303跟踪1---[or-http-epoll-2]
o、 s.c.g.f.WeightCalculatorWebFilter:权重属性:{}2019-10-13
18:29:38.305跟踪1---[or-http-epoll-2]
o、 s.c.g.h.路线预测手柄映射:未找到路线定义
交换:得到
虽然当我打电话给
http:///services
,然后我可以看到所有服务的列表。因此,所有权限都是在pod级别提供的,服务发现工作正常。我非常确定有一些配置,我缺少这些配置,但即使在查看了几次文档之后,我也无法找到它。所以,Spring Cloud Hoxton.M3版本中似乎存在问题,因为它与Hoxton.M2的配合良好
我已经打开了一个相同的应用程序。这可能不是问题所在,但您使用的是不匹配的spring Cloud版本。让bom表处理spring Cloud版本kubernetes@spencergibb如果我错了,请更正。我已删除了行
mavenBom“org.springframework.cloud:spring-cloud-kubernetes依赖项:${springCloudKubernetesVersion}“
fromimports
但它仍然不工作。