假设有一个外部服务,外部服务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.90
labels:
version: v1
ports:
http: 32033
- address: 10.10.102.90
labels:
version: v2
ports:
http: 32034
hosts:
- gin.test.ch
location: MESH_EXTERNAL
ports:
- name: http
number: 80
protocol: HTTP
resolution: STATIC
gateway
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: gin-egressgateway
spec:
selector:
istio: egressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- gin.test.ch
dr
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: egressgateway-for-gin
namespace: istio-system
spec:
host: istio-egressgateway-1-19-6.istio-system.svc.cluster.local
subsets:
- name: gin
vs
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: direct-gin-through-egress-gateway
spec:
gateways:
- gin-egressgateway
- mesh
hosts:
- gin.test.ch
http:
- match:
- gateways:
- mesh
port: 80
route:
- destination:
host: istio-egressgateway-1-19-6.istio-system.svc.cluster.local
port:
number: 80
subset: gin
weight: 100
- match:
- gateways:
- gin-egressgateway
port: 80
route:
- destination:
host: gin.test.ch
port:
number: 80
weight: 100