入口网关(Ingress Gateway)是 Istio 重要的资源对象之一,是用于管理网格边缘入站的流量,通过入口网关就可以很轻松的将网格内部的服务暴露到外部提供访问。
通过例子来理解
配置参数详解:
https://skyao.io/learning-istio/crd/network/sidecar.html
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: nginx-gw
spec:
selector: #用一个或者多个标签来选择一组pod或者虚拟机
app: istio-ingressgateway
servers: #server定义列表
- port: 代理服务器监听的端口
number: 80
name: http
protocol: HTTP
hosts: #gateway公开的主机名列表
- nginx.test.com
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: nginx-vs
spec:
hosts: #流量目标主机
- nginx.test.com
gateways: #Gate名称列表,Sidecar会根据这个来路由
- nginx-gw
http: #HTTP流量规则的有序列表
- route:
- destination:
host: nginx-svc
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: 'nginx:latest'
name: nginx-deployment
通过命令访问 curl -H “Host: nginx.gateway.com” http://ingressgateway:nodeport/
istio-ingressgateway 就是小区的大门(唯一的大门),所有进入的流量都需要经过, ingressgateway
相当于路标引导去到A B C D的一栋建筑里面,分开域名去导流, virtualservice
就像到建筑里的电梯一样,按照不同的楼层进行管理路由的作用, destinationrule 到达具体的楼层后按照不同的门房号 1 2 3 4
进入到真正的屋里去。
那么 Istio 网关是怎样工作的?请求如何到达它想要的应用程序?基本步骤如下:
1.客户端在特定端口上发出请求;
2.负载均衡器在这个端口上进行侦听,并将请求转发到集群中(在相同或新的端口);
3.在集群内部,请求被路由到 Istio IngressGateway 服务所侦听的负载均衡器转发过来的端口上;
4.Istio IngressGateway 服务将请求(在相同或新的端口)转发到对应的 pod 上;
5.在 IngressGateway pod 上会配置 Gateway 资源和 VirtualService 资源定义。Gateway 会配置端口、协议以及相关安全证书。VirtualService 的路由配置信息用于找到正确的服务;
6.Istio IngressGateway pod 会根据路由配置信息将请求路由到对应的应用服务上;
7.应用服务将请求路由到对应的应用 pod 上。
原文链接:https://blog.csdn.net/qq_50119948/article/details/116238871