假设有一个外部服务,外部服务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.90
    labels:
      version: v1
    ports:
      http: 32033
  - address: 10.10.102.90
    labels:
      version: v2
    ports:
      http: 32034
  hosts:
  - gindemo.test.ch
  location: MESH_EXTERNAL
  ports:
  - name: http
    number: 80
    protocol: HTTP
  resolution: STATIC

使用dr定义多版本:

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: gindemo-destination-rule
spec:
  host: gindemo.test.ch
  subsets:
  - labels:
      version: v1
    name: v1
  - labels:
      version: v2
    name: v2
  trafficPolicy:
    loadBalancer:
      simple: RANDOM

在vs中定义路由规则:

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: gindemo-virtual-service
spec:
  gateways:
  - mesh
  hosts:
  - gindemo.test.ch
  http:
  - match:
    - headers:
        x-version:
          exact: v1
      port: 80
    route:
    - destination:
        host: gindemo.test.ch
        subset: v1
  - match:
    - headers:
        x-version:
          exact: v2
      port: 80
    route:
    - destination:
        host: gindemo.test.ch
        subset: v2

访问:

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部