网关
网关
描述了在网格边缘运行的负载均衡器,它接收传入或传出的 HTTP/TCP 连接。规范描述了一组应公开的端口、要使用的协议类型、负载均衡器的 SNI 配置等。
例如,以下网关配置设置了一个代理,该代理充当负载均衡器,公开端口 80 和 9080 (http)、443 (https)、9443(https) 以及端口 2379 (TCP) 用于入口。网关将应用于在具有标签 app: my-gateway-controller
的 Pod 上运行的代理。虽然 Istio 将配置代理以监听这些端口,但用户有责任确保允许外部流量进入这些端口进入网格。
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: my-gateway
namespace: some-config-namespace
spec:
selector:
app: my-gateway-controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- uk.bookinfo.com
- eu.bookinfo.com
tls:
httpsRedirect: true # sends 301 redirect for http requests
- port:
number: 443
name: https-443
protocol: HTTPS
hosts:
- uk.bookinfo.com
- eu.bookinfo.com
tls:
mode: SIMPLE # enables HTTPS on this port
serverCertificate: /etc/certs/servercert.pem
privateKey: /etc/certs/privatekey.pem
- port:
number: 9443
name: https-9443
protocol: HTTPS
hosts:
- "bookinfo-namespace/*.bookinfo.com"
tls:
mode: SIMPLE # enables HTTPS on this port
credentialName: bookinfo-secret # fetches certs from Kubernetes secret
- port:
number: 9080
name: http-wildcard
protocol: HTTP
hosts:
- "*"
- port:
number: 2379 # to expose internal service via external port 2379
name: mongo
protocol: MONGO
hosts:
- "*"
上面的网关规范描述了负载均衡器的 L4-L6 属性。然后可以将 虚拟服务
绑定到网关,以控制到达特定主机或网关端口的流量转发。
例如,以下 VirtualService 将流量从 https://uk.bookinfo.com/reviews
、https://eu.bookinfo.com/reviews
、http://uk.bookinfo.com:9080/reviews
、http://eu.bookinfo.com:9080/reviews
拆分为内部评论服务的两个版本(prod 和 qa),该服务在端口 9080 上运行。此外,包含 cookie“user: dev-123”的请求将被发送到 qa 版本中的特殊端口 7777。相同的规则也适用于网格内对“reviews.prod.svc.cluster.local”服务的请求。此规则适用于端口 443 和 9080。请注意,http://uk.bookinfo.com
将重定向到 https://uk.bookinfo.com
(即 80 重定向到 443)。
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: bookinfo-rule
namespace: bookinfo-namespace
spec:
hosts:
- reviews.prod.svc.cluster.local
- uk.bookinfo.com
- eu.bookinfo.com
gateways:
- some-config-namespace/my-gateway
- mesh # applies to all the sidecars in the mesh
http:
- match:
- headers:
cookie:
exact: "user=dev-123"
route:
- destination:
port:
number: 7777
host: reviews.qa.svc.cluster.local
- match:
- uri:
prefix: /reviews/
route:
- destination:
port:
number: 9080 # can be omitted if it's the only port for reviews
host: reviews.prod.svc.cluster.local
weight: 80
- destination:
host: reviews.qa.svc.cluster.local
weight: 20
以下 VirtualService 将到达(外部)端口 27017 的流量转发到内部 Mongo 服务器的端口 5555。此规则不适用于网格内部,因为网关列表省略了保留名称 mesh
。
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: bookinfo-mongo
namespace: bookinfo-namespace
spec:
hosts:
- mongosvr.prod.svc.cluster.local # name of internal Mongo service
gateways:
- some-config-namespace/my-gateway # can omit the namespace if gateway is in same namespace as virtual service.
tcp:
- match:
- port: 27017
route:
- destination:
host: mongo.prod.svc.cluster.local
port:
number: 5555
可以使用 hosts 字段中的命名空间/主机名语法限制可以绑定到网关服务器的虚拟服务集。例如,以下网关允许 ns1 命名空间中的任何虚拟服务绑定到它,同时仅限制 ns2 命名空间中具有 foo.bar.com 主机的虚拟服务绑定到它。
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: my-gateway
namespace: some-config-namespace
spec:
selector:
app: my-gateway-controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "ns1/*"
- "ns2/foo.bar.com"
网关
网关描述一个在网格边缘运行的负载均衡器,接收传入或传出的 HTTP/TCP 连接。
服务器
Server
描述给定负载均衡器端口上的代理的属性。例如,
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: my-ingress
spec:
selector:
app: my-ingressgateway
servers:
- port:
number: 80
name: http2
protocol: HTTP2
hosts:
- "*"
另一个示例
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: my-tcp-ingress
spec:
selector:
app: my-tcp-ingressgateway
servers:
- port:
number: 27018
name: mongo
protocol: MONGO
hosts:
- "*"
以下是端口 443 的 TLS 配置示例
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: my-tls-ingress
spec:
selector:
app: my-tls-ingressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
hosts:
- "*"
tls:
mode: SIMPLE
credentialName: tls-cert
端口
Port 描述服务的特定端口的属性。
ServerTLSSettings
ServerTLSSettings.TLSmode
代理强制执行的 TLS 模式
名称 | 描述 |
---|---|
PASSTHROUGH | 客户端呈现的 SNI 字符串将用作 VirtualService TLS 路由中的匹配条件,以确定服务注册表中的目标服务。 |
SIMPLE | 使用标准 TLS 语义的保护连接。在此模式下,握手期间不会请求客户端证书。 |
MUTUAL | 通过呈现用于身份验证的服务器证书,与下游建立使用双向 TLS 的安全连接。握手期间还将请求客户端证书,并且客户端必须发送至少一个有效证书。 |
AUTO_PASSTHROUGH | 类似于 passthrough 模式,但具有此 TLS 模式的服务器不需要关联的 VirtualService 来从 SNI 值映射到注册表中的服务。服务/子集/端口等目标详细信息编码在 SNI 值中。代理将转发到由 SNI 值指定的 upstream (Envoy) 集群(一组端点)。此服务器通常用于在彼此之间没有直接连接的独立 L3 网络中的服务之间提供连接。使用此模式假设源和目标都使用 Istio mTLS 来保护流量。 |
ISTIO_MUTUAL | 通过呈现用于身份验证的服务器证书,来自下游的保护连接使用双向 TLS。与 Mutual 模式相比,此模式使用 Istio 自动为 mTLS 身份验证生成的证书,代表网关工作负载身份。使用此模式时, |
OPTIONAL_MUTUAL | 类似于 MUTUAL 模式,只是客户端证书是可选的。与 SIMPLE 模式不同,握手期间仍将明确请求客户端证书,但客户端无需发送证书。如果呈现客户端证书,则将对其进行验证。ca_certificates 应指定用于验证客户端证书。 |
ServerTLSSettings.TLSProtocol
TLS 协议版本。
名称 | 描述 |
---|---|
TLS_AUTO | 自动选择最佳 TLS 版本。 |
TLSV1_0 | TLS 版本 1.0 |
TLSV1_1 | TLS 版本 1.1 |
TLSV1_2 | TLS 版本 1.2 |
TLSV1_3 | TLS 版本 1.3 |