istio中serviceentry结合vs、dr实现多版本路由
假设有一个外部服务,外部服务ip为:10.10.102.90,其中32033为v1版本,32034为v2版本。
现在需要把这个服务引入到istio中,并且需要配置路由规则,使得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
使用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: gindemo-virtual-service
spec:gateways:- meshhosts:- gindemo.test.chhttp:- match:- headers:x-version:exact: v1port: 80route:- destination:host: gindemo.test.chsubset: v1- match:- headers:x-version:exact: v2port: 80route:- destination:host: gindemo.test.chsubset: v2
访问: