Istio Gateway 下的几种流量配置路径

1. 常用对象配置

1.1 Gateway

  • selector
    • 选择规则生效的 Envoy
  • servers
    • 匹配的域名
    • 端口
    • 协议
    • TLS 证书

1.2 VirtualService

  • gateways
    • 指定生效的网关,默认值 mesh 为东西向流量;如果指定 Gateway 对象则为南北向流量
  • http
    • 七层路由
    • 重定向
    • 重写
    • 重试
    • 条件规则
    • 超时
    • 故障注入
    • 跨站策略
  • tcp
    • 七层路由
  • tls
    • 带证书路由
    • TLS 证书

1.3 DestinationRule

  • host
    • 路由
  • trafficPolicy
    • 镜像流量
    • 故障转移
    • 熔断器
    • 负载均衡
  • subsets
    • 提供 Pod 分组,可用于蓝绿发布

2. 七层 Gateway->HTTPRoute->Service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: default-gateway
namespace: default
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- '*'
port:
name: http
number: 80
protocol: HTTP
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: chenshaowen
namespace: default
spec:
gateways:
- default/default-gateway
hosts:
- 'istio.chenshaowen.com'
http:
- match:
- uri:
exact: /
route:
- destination:
host: blog.default.svc.cluster.local
port:
number: 80

这样就将 default 空间下的 blog 服务通过 Istio Gateway 暴露到了外部。通过主机端口 + Istio Gateway 映射到主机的 NodePort 即可访问服务。如下图:

3. 四层 Gateway->TCPRoute->Service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: default-gateway
namespace: default
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- '*'
port:
name: tcp
number: 80
protocol: TCP
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: chenshaowen
namespace: default
spec:
gateways:
- default/default-gateway
hosts:
- 'istio.chenshaowen.com'
tcp:
- match:
- port: 80
route:
- destination:
host: blog.default.svc.cluster.local
port:
number: 80

当 VirtualService 中使用 TCP 时,Gateway 也需要使用 TCP ,协议需要匹配。