为所有主机开放 80 端口
除了istio: ingressgateway选择器之外,所有配置项的含义均不言自明。
通过使用这个选择器,我们可以指定哪个 Ingress 网关使用该配置,在我们的场景中,
也就是在 Istio 安装时的默认 Ingress 网关控制器。
# cat http-gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: http-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
# kubectl create -f http-gateway.yaml
网关已准备好接收流量,必须告知它将收到的流量发往何处,Istio使用名为“VirtualService”类型配置流量发往何处。
将一个网关列表配置给VirtualService,然后Istio使用VirtualService配置中定义的路由再配置那些网关.
VirtualService 资源
VirtualService 能够指导 Ingress 网关如何路由允许进入集群的请求
URI路径前缀匹配/
的将发往指定目标
注意: 如果有多个virtualservice文件,后面的会覆盖前面的,所以要把所有的路由信息都配置到一个virtualservice
# cat web-virtualservice-external.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: web-app
spec:
hosts:
- "*"
gateways:
- http-gateway
http:
- match:
- uri:
exact: /
route:
- destination:
host: nginx-web
# kubectl create -f web-virtualservice-external.yaml
或者只访问 v1 版本
# vim web-virtualservice-external.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: http-web
spec:
hosts:
- "*"
gateways:
- http-gateway
http:
- match:
- uri:
exact: /
route:
- destination:
host: nginx-web
port:
number: 80
subset: v1
从外部访问
gateway 把指定的URL 告诉 ingress pod处理。 virtualservice对指定URL进行 service 调用
-
- Gateway: Istio Gateway是负责打开k8s上相关Istio的pods(pod!pod!pod!)上的端口并接收主机的流量,是接收流量与路由之间的关键链接。
-
- VirtualService: Istio VirtualService是“附加”到Gateway上的,并负责定义Gateway应实现的路由。可以将多个VirtualServices连接到Gateway,但不适用于同一个域
### 有时候配置生效并更新 envoy 缓存会耗费一点时间
curl 10.113.2.179:31380/
nodeIP:istio-ingressgateway的nodeport/路径