配置用于入口流量的注入式网关

当通过网关注入安装网关时,可以通过结合使用 Istio 的 GatewayVirtualService 资源来配置它以处理入口流量。Istio 的 Gateway 资源定义了一个在网格边缘运行的负载均衡器,用于处理传入或传出的 HTTP/TCP 连接。Gateway 规范描述了一组要暴露的端口、使用的协议以及负载均衡器的服务器名称指示(SNI)设置。VirtualServices 用于为 Istio Gateway 定义路由规则,类似于它们为网格内流量定义路由规则的方式。

在下面的示例中,Istio Gateway 资源配置了一个网关代理,作为外部流量的入口点。该配置暴露了端口 443(HTTPS),用于 bookinfo.com 主机。该配置适用于带有标签 istio: ingressgateway 的 Pod。tls 模式设置为 SIMPLE,表示使用提供的 TLS Secret 终止传入的 HTTPS 流量。

示例配置

apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
  name: bookinfo-gateway
  namespace: bookinfo
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 443
        name: https-443
        protocol: HTTPS
      hosts:
        - bookinfo.com
      tls:
        mode: SIMPLE
        credentialName: bookinfo-credential

下面的 VirtualService 与前面配置示例中的 Istio Gateway 资源关联。其规范创建了规则,将路径前缀为 /reviews/ 的流量路由到 bookinfo 命名空间内的 reviews 服务。该 VirtualService 明确引用了之前展示的 Gateway 资源,确保这些路由规则仅适用于通过该特定网关进来的流量。

示例配置

kind: VirtualService
metadata:
  name: bookinfo-rule
  namespace: bookinfo
spec:
  hosts:
    - bookinfo.com
  gateways:
    - bookinfo/bookinfo-gateway
  http:
    - match:
        - uri:
            prefix: /reviews/
      route:
        - destination:
            port:
              number: 9080
            host: reviews.bookinfo.svc.cluster.local