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.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

定义一个egress gateway:

bash 复制代码
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: gindemo-egressgateway
spec:
  selector:
    istio: egressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - gindemo.test.ch

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

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

bash 复制代码
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: egressgateway-for-gindemo
  namespace: istio-system
spec:
  host: istio-egressgateway-1-19-6.istio-system.svc.cluster.local
  subsets:
  - name: gindemo
  trafficPolicy:
    loadBalancer:
      simple: RANDOM

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

bash 复制代码
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,定义服务路由规则:

bash 复制代码
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: direct-gindemo-through-egress-gateway
spec:
  gateways:
  - gindemo-egressgateway # 接收来自网关的流量
  - mesh # 接收来自网格内的流量
  hosts:
  - gindemo.test.ch
  http:
  - match: # 该match实现将来自网格内的流量,转发到egressgateway
    - gateways:
      - mesh 
      port: 80
    route:
    - destination:
        host: istio-egressgateway-1-19-6.istio-system.svc.cluster.local
        port:
          number: 80
        subset: gindemo
      weight: 100
  - match: # 该match实现将来自egressgateway的流量转发到serviceentry
    - gateways:
      - gindemo-egressgateway
      headers:
        x-version:
          exact: v1
    route:
    - destination:
        host: gindemo.test.ch
        subset: v1
  - match: # 该match实现将来自egressgateway的流量转发到serviceentry
    - gateways:
      - gindemo-egressgateway
      headers:
        x-version:
          exact: v2
      port: 80
    route:
    - destination:
        host: gindemo.test.ch
        subset: v2
相关推荐
lin_dec+7 小时前
Serverless:零成本按需计算的未来
云原生·serverless
迷藏49410 小时前
**eBPF实战进阶:从零构建网络流量监控与过滤系统**在现代云原生架构中,**网络可观测性**和**安全隔离**已成为
java·网络·python·云原生·架构
刘~浪地球10 小时前
架构设计--事件驱动架构设计与实现(05)
云原生·系统架构·云计算
鬼先生_sir10 小时前
Zookeeper:从入门到精通
分布式·zookeeper·云原生
marsh020610 小时前
31 openclaw微服务架构实践:构建分布式系统
微服务·ai·云原生·架构·编程·技术
开心码农1号12 小时前
k8s中service和ingress的区别和使用
云原生·容器·kubernetes
AI精钢15 小时前
为何智能体需要 Dreaming 来优化记忆?
人工智能·云原生·aigc
Henb92915 小时前
# 云原生大数据平台搭建
大数据·云原生
sbjdhjd15 小时前
Docker | 核心概念科普 + 保姆级部署
linux·运维·服务器·docker·云原生·面试·eureka
cyber_两只龙宝16 小时前
【Nginx】Nginx实现FastCGI详解
linux·运维·nginx·云原生·php·memcached·fastcgi