欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 名人名企 > istio中使用serviceentry结合egressgateway实现多版本路由

istio中使用serviceentry结合egressgateway实现多版本路由

2024/10/25 12:21:24 来源:https://blog.csdn.net/LONG_Yi_1994/article/details/142319590  浏览:    关键词:istio中使用serviceentry结合egressgateway实现多版本路由

假设有一个外部服务,外部服务ip为:10.10.102.90,其中32033为v1版本,32034为v2版本。

现在需要把这个服务引入到istio中,使用egressgateway转发访问该服务的流量,并且需要实现多版本路由,使得header中x-version的值为v1的路由到v1版本,x-version的值为v2的路由到v2版本。

使用serviceentry引入该服务

apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:name: gindemo-service-entry
spec:endpoints:- address: 10.10.102.90labels:version: v1ports:http: 32033- address: 10.10.102.90labels:version: v2ports:http: 32034hosts:- gindemo.test.chlocation: MESH_EXTERNALports:- name: httpnumber: 80protocol: HTTPresolution: STATIC

定义一个egress gateway:

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:name: gindemo-egressgateway
spec:selector:istio: egressgatewayservers:- port:number: 80name: httpprotocol: HTTPhosts:- gindemo.test.ch

创建一个dr,作为流量入口,接收网格内请求外部服务的流量:

注意!该dr需要在创建在istio-system命名空间下

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:name: egressgateway-for-gindemonamespace: istio-system
spec:host: istio-egressgateway-1-19-6.istio-system.svc.cluster.localsubsets:- name: gindemotrafficPolicy:loadBalancer:simple: RANDOM

创建服务的dr,声明服务的多个版本:

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:name: gindemo-destination-rule
spec:host: gindemo.test.chsubsets:- labels:version: v1name: v1- labels:version: v2name: v2trafficPolicy:loadBalancer:simple: RANDOM

创建一个vs,定义服务路由规则:

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:name: direct-gindemo-through-egress-gateway
spec:gateways:- gindemo-egressgateway # 接收来自网关的流量- mesh # 接收来自网格内的流量hosts:- gindemo.test.chhttp:- match: # 该match实现将来自网格内的流量,转发到egressgateway- gateways:- mesh port: 80route:- destination:host: istio-egressgateway-1-19-6.istio-system.svc.cluster.localport:number: 80subset: gindemoweight: 100- match: # 该match实现将来自egressgateway的流量转发到serviceentry- gateways:- gindemo-egressgatewayheaders:x-version:exact: v1route:- destination:host: gindemo.test.chsubset: v1- match: # 该match实现将来自egressgateway的流量转发到serviceentry- gateways:- gindemo-egressgatewayheaders:x-version:exact: v2port: 80route:- destination:host: gindemo.test.chsubset: v2

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com