将Spring云网关路由迁移到Kubernetes入口路由
我目前正在使用SpringCloudGateway来处理我的路由,我正在努力找出如何在Kubernetes Ingress中创建重写规则。我的SpringGateway逻辑如下所示 当前Spring网关路由将Spring云网关路由迁移到Kubernetes入口路由,kubernetes,kubernetes-ingress,spring-cloud-gateway,Kubernetes,Kubernetes Ingress,Spring Cloud Gateway,我目前正在使用SpringCloudGateway来处理我的路由,我正在努力找出如何在Kubernetes Ingress中创建重写规则。我的SpringGateway逻辑如下所示 当前Spring网关路由 spring: application: name: gateway-service cloud: gateway: routes: - id: clover-service uri: http://domain:950
spring:
application:
name: gateway-service
cloud:
gateway:
routes:
- id: clover-service
uri: http://domain:9500
predicates:
- Path=/portal/api/clover/**
filters:
//Rewrite to http://domain:9500/api/clover
- RewritePath=/portal(?<segment>/?.*), $\{segment}
- id: auth-svc
uri: http://domain:8900
predicates:
- Path=/portal/auth/**
filters:
//Rewrite to http://domain:8900/auth
- RewritePath=/portal/auth(?<segment>/?.*), $\{segment}
######################################################
## ##
## The default goes to the nuxt frontend app ##
## ##
######################################################
- id: frontend
uri: http://domain:3000
predicates:
- Path=/**
似乎重写目标正在重写我的所有路由,而不是单个路由。有人知道如何重写单独的路由吗?看看Kubernetes中的定义
Kubernetes中的Official入口配置不支持此选项。但您可以使用支持spring注释的其他实现的入口网关。您可以在此处找到更多信息:
您的Ingress配置文件应该包括注释,如kubernetes.io/Ingress.class:spring.cloud.gateway
和spring.cloud.gateway/routes
以下是示例入口配置文件:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: httpbin
namespace: ingress
annotations:
kubernetes.io/ingress.class: spring.cloud.gateway
spring.cloud.gateway/routes: |
predicates:
- Host=httpbin.nlighten.nl
- Path=/{segment}
filters:
- SetPath=/anything/{segment}
- PreserveHostHeader
- SecureHeaders
- name: Retry
args:
retries: 3
statuses: BAD_GATEWAY
uri: lb://httpbin
spec:
backend:
serviceName: httpbin
servicePort: 80
记住在适当的名称空间中创建入口。网关和后端必须在同一命名空间中运行
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: httpbin
namespace: ingress
annotations:
kubernetes.io/ingress.class: spring.cloud.gateway
spring.cloud.gateway/routes: |
predicates:
- Host=httpbin.nlighten.nl
- Path=/{segment}
filters:
- SetPath=/anything/{segment}
- PreserveHostHeader
- SecureHeaders
- name: Retry
args:
retries: 3
statuses: BAD_GATEWAY
uri: lb://httpbin
spec:
backend:
serviceName: httpbin
servicePort: 80