如何配置 Istio 虚拟服务目标协议
How to configure Istio Virtual Service destination protocol
如何配置 Istio VirtualService 以将流量路由到侦听 HTTPS 的目标后端?
配置 protocol: HTTPS
或 scheme: HTTPS
无效。
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: api-rpi-access
spec:
hosts:
- "test.example.com"
gateways:
- api-gateway
http:
- match:
- uri:
port: https
prefix: /
route:
- destination:
host: some-https-service
port:
number: 8443
protocol: HTTPS
# scheme: HTTPS
这是我的网关:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: api-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
tls:
mode: SIMPLE
serverCertificate: /etc/istio/ingressgateway-certs/tls.crt
privateKey: /etc/istio/ingressgateway-certs/tls.key
hosts:
- "test.example.com"
您是否也设置了目标规则,例如:
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: dr-test.example.com
spec:
host: test.example.com
trafficPolicy: # Apply to all ports
portLevelSettings:
- port:
number: 443
loadBalancer:
simple: LEAST_CONN
当前您的网关配置为在网关上终止 TLS。您的 VirtualService 也需要少量修改。
您需要将网关的 TLS 模式更改为直通。
tls:
mode: PASSTHROUGH
根据 istio 文档:
- Define a
Gateway
with a server
section for port 443. Note the PASSTHROUGH
TLS mode which instructs the gateway to pass the ingress traffic AS IS, without terminating TLS.
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: mygateway
spec:
selector:
istio: ingressgateway # use istio default ingress gateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
tls:
mode: PASSTHROUGH
hosts:
- nginx.example.com
- Configure routes for traffic entering via the
Gateway
:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: nginx
spec:
hosts:
- nginx.example.com
gateways:
- mygateway
tls:
- match:
- port: 443
sniHosts:
- nginx.example.com
route:
- destination:
host: my-nginx
port:
number: 443
希望对您有所帮助。
为了在 istio ingressgateway 上执行 LTS 终止并将 https 流量发送到后端,我必须添加以下 DestinationRule
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: some-https-service
spec:
host: diary
trafficPolicy:
tls:
mode: SIMPLE
这里是网关和虚拟服务:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: api-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
tls:
mode: SIMPLE
serverCertificate: /etc/istio/ingressgateway-certs/tls.crt
privateKey: /etc/istio/ingressgateway-certs/tls.key
hosts:
- "test.example.com"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ext-access
spec:
hosts:
- "test.example.com"
gateways:
- api-gateway
http:
- match:
- uri:
port: https
prefix: /
route:
- destination:
host: some-https-service
port:
number: 8443
如何配置 Istio VirtualService 以将流量路由到侦听 HTTPS 的目标后端?
配置 protocol: HTTPS
或 scheme: HTTPS
无效。
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: api-rpi-access
spec:
hosts:
- "test.example.com"
gateways:
- api-gateway
http:
- match:
- uri:
port: https
prefix: /
route:
- destination:
host: some-https-service
port:
number: 8443
protocol: HTTPS
# scheme: HTTPS
这是我的网关:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: api-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
tls:
mode: SIMPLE
serverCertificate: /etc/istio/ingressgateway-certs/tls.crt
privateKey: /etc/istio/ingressgateway-certs/tls.key
hosts:
- "test.example.com"
您是否也设置了目标规则,例如:
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: dr-test.example.com
spec:
host: test.example.com
trafficPolicy: # Apply to all ports
portLevelSettings:
- port:
number: 443
loadBalancer:
simple: LEAST_CONN
当前您的网关配置为在网关上终止 TLS。您的 VirtualService 也需要少量修改。
您需要将网关的 TLS 模式更改为直通。
tls:
mode: PASSTHROUGH
根据 istio 文档:
- Define a
Gateway
with aserver
section for port 443. Note thePASSTHROUGH
TLS mode which instructs the gateway to pass the ingress traffic AS IS, without terminating TLS.apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: mygateway spec: selector: istio: ingressgateway # use istio default ingress gateway servers: - port: number: 443 name: https protocol: HTTPS tls: mode: PASSTHROUGH hosts: - nginx.example.com
- Configure routes for traffic entering via the
Gateway
:apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: nginx spec: hosts: - nginx.example.com gateways: - mygateway tls: - match: - port: 443 sniHosts: - nginx.example.com route: - destination: host: my-nginx port: number: 443
希望对您有所帮助。
为了在 istio ingressgateway 上执行 LTS 终止并将 https 流量发送到后端,我必须添加以下 DestinationRule
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: some-https-service
spec:
host: diary
trafficPolicy:
tls:
mode: SIMPLE
这里是网关和虚拟服务:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: api-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
tls:
mode: SIMPLE
serverCertificate: /etc/istio/ingressgateway-certs/tls.crt
privateKey: /etc/istio/ingressgateway-certs/tls.key
hosts:
- "test.example.com"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ext-access
spec:
hosts:
- "test.example.com"
gateways:
- api-gateway
http:
- match:
- uri:
port: https
prefix: /
route:
- destination:
host: some-https-service
port:
number: 8443