istio通过Gateway和VirtualService代理tcp端口

1.新建gw和vs

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:name: tcp-gatewaynamespace: ns
spec:selector:istio: ingressgatewayservers:- hosts:- tcp.xx.xx.xx   #域名port:name: gateway-tcpnumber: 9099   #istio代理tcp端口的端口protocol: TCP
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:name: tcp-vsnamespace: ns
spec:gateways:- ck-tcp-gatewayhosts:- tcp.xx.xx.xx  #域名tcp:- match:- port: 9099   #istio代理tcp端口的端口route:- destination:host: my-server.ns.svc.cluster.localport:number: 9000   #需要代理的服务的tcp端口

 

2.修改istio-ingressgateway的svc

新增一个监听端口和nodeport

  - name: tcp-testnodePort: 20099port: 9099protocol: TCPtargetPort: 9099

 

3.测试

#端口为上面新加的tcp端口的nodeport
curl -H "Host:tcp.xx.xx.xx" http://10.10.10.10:20099