配置Istio以进行外部路由

将Istio配置为入口控制器,以便从Kubernetes集群外部访问您的Redis Enterprise数据库。

Redis Enterprise for Kubernetes 能够使用 Istio Ingress 网关作为 NGINX 或 HaProxy Ingress 控制器的替代方案。

Istio 也可以理解 Ingress 资源,但使用该机制会失去原生 Istio 资源提供的优势和选项。Istio 提供了使用自定义资源的配置方法。

要配置Istio以与Redis Kubernetes操作符一起工作,我们将使用两个自定义资源:一个Gateway和一个VirtualService。然后,您将能够建立对数据库的外部访问。

为Redis Enterprise安装和配置Istio

  1. Downloadinstall Istio(请参阅 Istio 的 Getting Started 指南中的说明)。

    安装完成后,所有的部署、pod和服务都将部署在一个名为istio-system的命名空间中。这个命名空间包含一个名为service/istio-ingressgatewayLoadBalancer类型服务,该服务暴露了外部IP地址。

  2. 找到istio-ingressgateway服务的EXTERNAL-IP

    kubectl get svc istio-ingressgateway -n istio-system
    
    NAME                   TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                                                                      AGE
    istio-ingressgateway   LoadBalancer   10.34.67.89   10.145.78.91   15021:12345/TCP,80:67891/TCP,443:23456/TCP,31400:78901/TCP,15443:10112/TCP   3h8m
    
  3. 创建一个DNS条目,将您选择的数据库主机名(或通配符*后跟您的域名)解析为Istio的EXTERNAL-IP。使用此主机名从集群外部访问您的数据库。

    在这个例子中,任何以.istio.k8s.my.example.com结尾的主机名都将解析为Istio LoadBalancer的外部IP地址10.145.78.91。请相应地替换为您自己的值。

  4. 验证记录是否成功创建。

    dig api.istio.k8s.my.example.com
    

    ANSWER SECTION中查找您刚刚创建的记录。

    ;; ANSWER SECTION:
    api.istio.k8s.my.example.com 0 IN    A       10.145.78.91
    

创建自定义资源

Gateway 自定义资源

  1. 在与istio-system不同的命名空间上,创建一个Gateway自定义资源文件(在本例中为redis-gateway.yaml)。

    • .istio.k8s.my.example.com 替换为与您的DNS记录匹配的域名。
    • <selector-label> 替换为您的 Istio 入口网关 pod 上设置的标签(最常见的是 istio: ingress)。
    • 需要TLS直通模式以允许安全访问数据库。
    apiVersion: networking.istio.io/v1beta1
    kind: Gateway
    metadata:
      name: redis-gateway
    spec:
      selector:
        istio: <selector-label>
      servers:
      - hosts:
        - '*.istio.k8s.my.example.com'
        port:
          name: https
          number: 443
          protocol: HTTPS
        tls:
          mode: PASSTHROUGH
    
  2. 应用Gateway自定义资源文件来创建Ingress网关。

    kubectl apply -f redis-gateway.yaml
    
  3. 验证网关是否成功创建。

    kubectl get gateway
    
    NAME            AGE
    redis-gateway   3h33m
    

VirtualService 自定义资源

  1. 在与istio-system不同的命名空间上,创建VirtualService自定义资源文件(在本例中为redis-vs.yaml)。

    apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: redis-vs
    spec:
      gateways:
      - redis-gateway
      hosts:
      - "*.istio.k8s.my.example.com"
      tls:
      - match:
        - port: 443
          sniHosts:
          - api.istio.k8s.my.example.com
        route:
        - destination:
            host: rec1
            port:
              number: 9443
      - match:
        - port: 443
          sniHosts:
          - db1.istio.k8s.my.example.com
        route:
        - destination:
            host: db1
    

    这创建了一个用于联系REC上的API服务器的路由(rec1)和一个用于联系其中一个数据库的路由(db1)。

    • .istio.k8s.my.example.com 替换为与您的DNS记录匹配的域名。
    • 网关的元数据名称必须与网关的规范名称相似(在此示例中为redis-gateway)。
  2. 应用VirtualService自定义资源文件来创建虚拟服务。

    kubectl apply -f redis-vs.yaml
    
  3. 验证虚拟服务是否成功创建。

    kubectl get vs
    
    NAME       GATEWAYS            HOSTS                              AGE
    redis-vs   ["redis-gateway"]   ["*.istio.k8s.my.example.com"]   3h33m
    
  4. 部署操作符、Redis企业集群(REC)和Redis企业数据库(REDB)在与网关和虚拟服务相同的命名空间上。

测试您对数据库的外部访问

测试你的外部访问数据库,你需要一个支持TLSSNI的客户端。

请参阅使用Openssl测试您的访问权限使用Python测试您的访问权限以获取更多信息。

RATE THIS PAGE
Back to top ↑