K8s除了自帶的Ingress Gateway外,還可以透過Istio Ingress Gateway可以使用,
Istio Ingress Gateway除了有k8s Ingress Gateway的功能外,還額外多了進階的流動路由與其他功能。
Istio Ingress Gateway 本身支援L4到L6的功能,例如Expose Port,TLS..etc,但是Istio Ingress Gateway可以前面有提到的Virtual Service結合,而Virtual Service 可以設定L7,ex Request Routing
,Fault Injection
,Traffic Shifting
,TCP Traffic Shifting
...,可以在istio官方文件看到
traffic-management,
簡單說,Istio Ingress Gateway + virtual Service 的組合做的比k8s ingress gateway更好,如果都裝Istio,就直接上Istio Ingress Gateway吧
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway # 這邊是指Ingress Gateway的名稱喔
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*" # 這邊根據你的host來使用,如果你的ingress gateway解析domain叫"www.mytestingress.net",這邊的*就是www.mytestingress.net
基本上Gateway跟Virtual Service可以寫在同一份yaml上面同時部署上去
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- "*"
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /productpage
route:
- destination:
host: productpage
port:
number: 9080
基本上Istio的Gateway跟Virtual Service就可以完成初步的導流動作,後面就會繼續介紹它的額外功能啦