假设有一个外部服务,外部服务ip为:10.10.102.90,其中32033为v1版本,32034为v2版本。
现在需要把这个服务引入到istio中,并且需要配置所有访问该服务的流量都通过egressgateway转发出去。
serviceentry
apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:name: gin-service-entry
spec:endpoints:- address: 10.10.102.90labels:version: v1ports:http: 32033- address: 10.10.102.90labels:version: v2ports:http: 32034hosts:- gin.test.chlocation: MESH_EXTERNALports:- name: httpnumber: 80protocol: HTTPresolution: STATIC
gateway
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:name: gin-egressgateway
spec:selector:istio: egressgatewayservers:- port:number: 80name: httpprotocol: HTTPhosts:- gin.test.ch
dr
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:name: egressgateway-for-ginnamespace: istio-system
spec:host: istio-egressgateway-1-19-6.istio-system.svc.cluster.localsubsets:- name: gin
vs
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:name: direct-gin-through-egress-gateway
spec:gateways:- gin-egressgateway- meshhosts:- gin.test.chhttp:- match:- gateways:- meshport: 80route:- destination:host: istio-egressgateway-1-19-6.istio-system.svc.cluster.localport:number: 80subset: ginweight: 100- match:- gateways:- gin-egressgatewayport: 80route:- destination:host: gin.test.chport:number: 80weight: 100