简单示例
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
Gateway配置信息
Field | Type | Description | Required |
---|---|---|---|
servers | Server[] | 开放的服务列表 | 是 |
selector | map | 通过这个Label来找到执行 Gateway 规则的 Envoy | 是 |
Server 配置信息
Field | Type | Description | Required |
---|---|---|---|
port | Port | 服务对外监听的端口 | 是 |
hosts | string[] | Gateway 发布的服务地址,是一个 FQDN 域名,可以支持左侧通配符来进行模糊查询 | 是 |
tls | TLSOptions | TLS安全配置 | 否 |
defaultEndpoint | string | 默认情况下,应将流量转发到的环回IP端点或Unix域套接字 | 否 |
Port 配置信息
Field | Type | Description | Required |
---|---|---|---|
number | uint32 | 一个有效的端口号 | 是 |
protocol | string | 所使用的协议,支持HTTP/HTTPS/GRPC/HTTP2/MONGO/TCP/TLS | 是 |
name | string | 给端口分配一个名称 | 否 |
Server.TLSOptions 配置信息
Field | Type | Description | Required |
---|---|---|---|
httpsRedirect | bool | 是否要做 HTTP 重定向 | 否 |
mode | TLSmode | 在配置的外部端口上使用 TLS 服务时,可以取 PASSTHROUGH、SIMPLE、MUTUAL、AUTO_PASSTHROUGH 这 4 种模式 | 否 |
serverCertificate | string | 服务端证书的路径。当模式是 SIMPLE 和 MUTUAL 时必须指定 | 否 |
privateKey | string | 服务端密钥的路径。当模式是 SIMPLE 和 MUTUAL 时必须指定 | 否 |
caCertificates | string | CA 证书路径。当模式是 MUTUAL 时指定 | 否 |
credentialName | string | 用于唯一标识服务端证书和秘钥。Gateway 使用 credentialName从远端的凭证存储中获取证书和秘钥,而不是使用 Mount 的文件 | 否 |
subjectAltNames | string[] | SAN 列表,SubjectAltName 允许一个证书指定多个域名 | 否 |
verifyCertificateSpki | string[] | 授权客户端证书的SKPI的base64编码的SHA-256哈希值的可选列表 | 否 |
verifyCertificateHash | string[] | 授权客户端证书的十六进制编码SHA-256哈希值的可选列表 | 否 |
minProtocolVersion | TLSProtocol | TLS 协议的最小版本 | 否 |
maxProtocolVersion | TLSProtocol | TLS 协议的最大版本 | 否 |
cipherSuites | string[] | 指定的加密套件,默认使用 Envoy 支持的加密套件 | 否 |
Server.TLSOptions.TLSmode 配置信息
Name | Description |
---|---|
PASSTHROUGH | 客户端提供的SNI字符串将用作VirtualService TLS路由中的匹配条件,以根据服务注册表确定目标服务 |
SIMPLE | 使用标准TLS语义的安全连接 |
MUTUAL | 通过提供服务器证书进行身份验证,使用双边TLS来保护与下游的连接 |
AUTO_PASSTHROUGH | 与直通模式相似,不同之处在于具有此TLS模式的服务器不需要关联的VirtualService即可从SNI值映射到注册表中的服务。目标详细信息(例如服务/子集/端口)被编码在SNI值中。代理将转发到SNI值指定的上游(Envoy)群集(一组端点)。 |
ISTIO_MUTUAL | 通过提供用于身份验证的服务器证书,使用相互TLS使用来自下游的安全连接 |
Server.TLSOptions.TLSProtocol 配置信息
Name | Description |
---|---|
TLS_AUTO | 自动选择DLS版本 |
TLSV1_0 | TLS 1.0 |
TLSV1_1 | TLS 1.1 |
TLSV1_2 | TLS 1.2 |
TLSV1_3 | TLS 1.3 |
istio-ingressgateway【入口网关】
入口网关HTTP
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
入口网关TLS直通
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: https
protocol: HTTPS #TLS协议
hosts:
- wistio.cc
tls:
mode: PASSTHROUGH #TLS直通
入口网关TLS终结【常用】
作用:将服务网络内部的一个HTTP的服务通过Gateway发布为HTTPS外部访问
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: https
protocol: HTTPS #TLS协议
hosts:
- wistio.cc
tls:
mode: SIMPLE #单向TLS
serverCertificate: /etc/istio/certs/server.pem
privateKey: /etc/istio/certs/server.key
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: https
protocol: HTTPS #TLS协议
hosts:
- wistio.cc
tls:
mode: MUTUAL #双向TLS
serverCertificate: /etc/istio/certs/server.pem
privateKey: /etc/istio/certs/server.key
caCertificates: /etc/istio/certs/kehu_server.pem #客户端证书
istio-egressgateway【出口网关】
出口网关HTTP
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: egressgateway-http
spec:
selector:
istio: egressgateway
servers:
- hosts:
- api.forecast.weather
port:
number: 1031
name: http
protocol: HTTP #HTTP协议
对应VirtualService
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: egress-weatherdb
spec:
gateways:
- istio-system/egressgateway-http
- mesh
hosts:
- api.forecast.weather
http:
- match:
- gateways:
- mesh
port: 9999 #Service Entry的服务端口
route:
- destination:
host: egressgateway-http.istio-system.svc.cluster.local
port:
number: 80 #Egress Gateway的服务端口
#内部流量:这个路由的gateways是mesh关键字,表示来自服务网络内部的流量,这类流量在访问api.forecast.weather这个外部地址时将被转发到Egress-gateway
- match:
- gateways:
- istio-system/egressgateway-http
port: 1031 #Egress Gateway的目标端口
route:
- destination:
host: api.forecast.weather
port:
number: 9999 #Service Entry的服务端口
#外部流量:这个路由匹配的gateways是egressgateway-http,表示匹配来自Egress-gateway的流量将被路由到服务网络外部服务api.forecast.weather
出口网关TLS
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: originate-tls-dr
spec:
host: api.forecast.weather
trafficPolicy:
portLevelSettings:
- port:
number: 9999
tls:
mode: SIMPLE
sni: api.forecast.weather