VS流量管理
Istio入流量方向
- Client -> IngressController -> Gateway -> VirtualService -> Service -> workload
1.创建网关
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: mygw
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "aa.xiebo.pro"
2.VirtualService用法
2.1.基础用法
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myvs
spec:
hosts:
- "aa.xiebo.pro"
gateways:
- mygw
http:
- route:
- destination:
host: svc1
2.2.前缀匹配转发访问目录
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myvs
spec:
hosts:
- "aa.xiebo.pro"
gateways:
- mygw
http:
- name: aaa
match:
- uri:
prefix: /demo1
route:
- destination:
host: svc1
- name: bbb
match:
- uri:
prefix: /demo2
route:
- destination:
host: svc2
2.3.权重转发负载
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myvs
spec:
hosts:
- "aa.xiebo.pro"
gateways:
- mygw
http:
#weight值之和必须为100
- route:
- destination:
host: svc1
weight: 50
- destination:
host: svc2
weight: 50
2.4.路径重写
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myvs
spec:
hosts:
- "aa.xiebo.pro"
gateways:
- mygw
http:
- match:
- uri:
prefix: /demo1
rewrite:
uri: /demo2
route:
- destination:
host: svc1
2.5.转发到其它命名空间
#创建ns2的VS
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: vs1
spec:
http:
- route:
- destination:
#host: svc1.ns2.svc.cluster.local
host: svc1
#配置ns1的VS 转发到ns2的VS
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myvs
spec:
hosts:
- "aa.xiebo.pro"
gateways:
- mygw
http:
- name: aaa
match:
- uri:
prefix: /demo1
delegate:
name: vs1
namespace: ns2
- route:
- destination:
host: svc1
2.6.基于http header
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myvs
spec:
hosts:
- "aa.xiebo.pro"
gateways:
- mygw
http:
- name: aaa
match:
- headers:
User-Agent:
regex: .*(Chrome/([\d.]+)).*
route:
- destination:
host: svc2
- route:
- destination:
host: svc1