28.5. 在 AWS 上配置集群入口流量

OpenShift Container Platform 提供了从集群外部与集群中运行的服务进行通信的方法。此方法使用 AWS 上的负载均衡器,特别是 Network Load Balancer(NLB)或 Classic Load Balancer(CLB)。两种负载均衡器都可以将客户端的 IP 地址转发到节点,但 CLB 需要支持代理协议(OpenShift Container Platform 会自动启用)。

将 Ingress Controller 配置为使用 NLB 的方法有两种:

  1. 通过强制替换当前使用 CLB 的 Ingress Controller。这会删除 IngressController 对象,并在新的 DNS 记录传播并置备 NLB 时发生停机。
  2. 通过编辑使用 CLB 的现有 Ingress Controller 以使用 NLB。这会更改负载均衡器而无需删除并重新创建 IngressController 对象。

两种方法都可用于从 NLB 切换到 CLB。

您可以在新的或现有 AWS 集群上配置这些负载均衡器。

28.5.1. 在 AWS 中配置 Classic Load Balancer 超时

OpenShift Container Platform 提供了为特定路由或 Ingress Controller 设置自定义超时时间的方法。另外,AWS Classic Load Balancer(CLB)都有自己的超时时间,默认的超时时间为 60 秒。

如果 CLB 的超时时间小于路由超时或 Ingress Controller 超时,负载均衡器可以预先终止连接。您可以通过增加路由和 CLB 的超时周期来防止此问题。

28.5.1.1. 配置路由超时

如果您的服务需要低超时(满足服务级别可用性 (SLA) 目的)或高超时(具有慢速后端的情况),您可以为现有路由配置默认超时。

前提条件

  • 您需要在运行的集群中部署了 Ingress Controller。

流程

  1. 使用 oc annotate 命令,为路由添加超时:

    $ oc annotate route <route_name> \
        --overwrite haproxy.router.openshift.io/timeout=<timeout><time_unit> 1
    1
    支持的时间单位是微秒 (us)、毫秒 (ms)、秒钟 (s)、分钟 (m)、小时 (h)、或天 (d)。

    以下示例在名为 myroute 的路由上设置两秒的超时:

    $ oc annotate route myroute --overwrite haproxy.router.openshift.io/timeout=2s

28.5.1.2. 配置 Classic Load Balancer 超时

您可以为 Classic Load Balancer(CLB)配置默认超时来扩展闲置连接。

先决条件

  • 您必须在正在运行的集群中部署了 Ingress Controller。

流程

  1. 运行以下命令,为默认的 ingresscontroller 设置 AWS 连接闲置超时:

    $ oc -n openshift-ingress-operator patch ingresscontroller/default \
        --type=merge --patch='{"spec":{"endpointPublishingStrategy": \
        {"type":"LoadBalancerService", "loadBalancer": \
        {"scope":"External", "providerParameters":{"type":"AWS", "aws": \
        {"type":"Classic", "classicLoadBalancer": \
        {"connectionIdleTimeout":"5m"}}}}}}}'
  2. 可选:运行以下命令来恢复超时的默认值:

    $ oc -n openshift-ingress-operator patch ingresscontroller/default \
        --type=merge --patch='{"spec":{"endpointPublishingStrategy": \
        {"loadBalancer":{"providerParameters":{"aws":{"classicLoadBalancer": \
        {"connectionIdleTimeout":null}}}}}}}'
注意

在更改连接超时值时,您必须指定 scope 字段,除非已经设置了当前范围。设置 scope 字段时,如果恢复默认的超时值,则不需要再次这样做。

28.5.2. 使用网络负载平衡器在 AWS 上配置集群入口流量

OpenShift Container Platform 提供了从集群外部与集群中运行的服务进行通信的方法。一个这样的方法是使用 Network Load Balancer(NLB)。您可以在新的或现有 AWS 集群上配置 NLB。

28.5.2.1. 将 Ingress Controller 从使用 Classic Load Balancer 切换到网络负载均衡器

您可以将使用 Classic Load Balancer (CLB) 的 Ingress Controller 切换到使用 AWS 上的网络负载平衡器 (NLB) 的 Ingress Controller。

在这些负载均衡器间切换不会删除 IngressController 对象。

警告

此过程可能会导致以下问题:

  • 由于新的 DNS 记录传播、新的负载均衡器置备和其他因素而可能需要几分钟的中断。应用此步骤后,Ingress Controller 负载均衡器的 IP 地址和规范名称可能会改变。
  • 由于服务注解的变化,会泄漏负载均衡器资源。

流程

  1. 修改您要使用 NLB 切换到的现有 Ingress Controller。这个示例假定您的默认 Ingress Controller 具有外部范围,且没有其他自定义:

    ingresscontroller.yaml 文件示例

    apiVersion: operator.openshift.io/v1
    kind: IngressController
    metadata:
      creationTimestamp: null
      name: default
      namespace: openshift-ingress-operator
    spec:
      endpointPublishingStrategy:
        loadBalancer:
          scope: External
          providerParameters:
            type: AWS
            aws:
              type: NLB
        type: LoadBalancerService

    注意

    如果您没有为 spec.endpointPublishingStrategy.loadBalancer.providerParameters.aws.type 字段指定值,Ingress Controller 会使用在安装过程中设置的集群 Ingress 配置中的 spec.loadBalancer.platform.aws.type 值。

    提示

    如果您的 Ingress Controller 有其他要更新的自定义(如更改域),请考虑强制替换 Ingress Controller 定义文件。

  2. 运行以下命令,将更改应用到 Ingress Controller YAML 文件:

    $ oc apply -f ingresscontroller.yaml

    当 Ingress Controller 更新时,可能会有几分钟的停机。

28.5.2.2. 将 Ingress Controller 从使用 Network Load Balancer 切换到使用 Classic Load Balancer

在 AWS 中,您可以将使用 Network Load Balancer (NLB) 的 Ingress Controller 切换到使用 Classic Load Balancer (CLB) 的 Ingress Controller。

在这些负载均衡器间切换不会删除 IngressController 对象。

警告

此流程会导致预期的中断会因为新的 DNS 记录传播、新的负载均衡器置备和其他因素而可能需要几分钟。应用此步骤后,Ingress Controller 负载均衡器的 IP 地址和规范名称可能会改变。

流程

  1. 修改您要切换为使用 CLB 的现有 Ingress Controller。这个示例假定您的默认 Ingress Controller 具有外部范围,且没有其他自定义:

    ingresscontroller.yaml 文件示例

    apiVersion: operator.openshift.io/v1
    kind: IngressController
    metadata:
      creationTimestamp: null
      name: default
      namespace: openshift-ingress-operator
    spec:
      endpointPublishingStrategy:
        loadBalancer:
          scope: External
          providerParameters:
            type: AWS
            aws:
              type: Classic
        type: LoadBalancerService

    注意

    如果您没有为 spec.endpointPublishingStrategy.loadBalancer.providerParameters.aws.type 字段指定值,Ingress Controller 会使用在安装过程中设置的集群 Ingress 配置中的 spec.loadBalancer.platform.aws.type 值。

    提示

    如果您的 Ingress Controller 有其他要更新的自定义(如更改域),请考虑强制替换 Ingress Controller 定义文件。

  2. 运行以下命令,将更改应用到 Ingress Controller YAML 文件:

    $ oc apply -f ingresscontroller.yaml

    当 Ingress Controller 更新时,可能会有几分钟的停机。

28.5.2.3. 将 Ingress Controller Classic Load Balancer 替换为网络负载均衡器

您可以将使用 Classic 负载平衡器(CLB)的 Ingress Controller 替换为 AWS 上使用网络负载平衡器(NLB)的 Ingress Controller。

警告

此过程可能会导致以下问题:

  • 由于新的 DNS 记录传播、新的负载均衡器置备和其他因素而可能需要几分钟的中断。应用此步骤后,Ingress Controller 负载均衡器的 IP 地址和规范名称可能会改变。
  • 由于服务注解的变化,会泄漏负载均衡器资源。

流程

  1. 创建一个新的默认 Ingress Controller 文件。以下示例假定您的默认 Ingress Controller 具有外部范围,且没有其他自定义:

    ingresscontroller.yml 文件示例

    apiVersion: operator.openshift.io/v1
    kind: IngressController
    metadata:
      creationTimestamp: null
      name: default
      namespace: openshift-ingress-operator
    spec:
      endpointPublishingStrategy:
        loadBalancer:
          scope: External
          providerParameters:
            type: AWS
            aws:
              type: NLB
        type: LoadBalancerService

    如果您的默认 Ingress Controller 有其他自定义,请确定您相应地修改该文件。

    提示

    如果您的 Ingress Controller 没有其他自定义,且您只更新负载均衡器类型,请考虑 "Switch the Ingress Controller from using an Classic Load Balancer to a Network Load Balancer" 中详述的步骤。

  2. 强制替换 Ingress Controller YAML 文件:

    $ oc replace --force --wait -f ingresscontroller.yml

    等待 Ingress Controller 已被替换。预计会有几分钟的停机时间。

28.5.2.4. 在现有 AWS 集群上配置 Ingress Controller 网络负载均衡器

您可以在当前集群中创建一个由 AWS Network Load Balancer(NLB)支持的 Ingress Controller。

先决条件

  • 您必须已安装 AWS 集群。
  • 基础架构资源的 PlatformStatus 需要是 AWS。

    • 要验证 PlatformStatus 是否为 AWS,请运行:

      $ oc get infrastructure/cluster -o jsonpath='{.status.platformStatus.type}'
      AWS

流程

在现有集群中,创建一个由 AWS NLB 支持的 Ingress Controller。

  1. 创建 Ingress Controller 清单:

     $ cat ingresscontroller-aws-nlb.yaml

    输出示例

    apiVersion: operator.openshift.io/v1
    kind: IngressController
    metadata:
      name: $my_ingress_controller1
      namespace: openshift-ingress-operator
    spec:
      domain: $my_unique_ingress_domain2
      endpointPublishingStrategy:
        type: LoadBalancerService
        loadBalancer:
          scope: External3
          providerParameters:
            type: AWS
            aws:
              type: NLB

    1
    $my_ingress_controller 替换为 Ingress Controller 的唯一名称。
    2
    $my_unique_ingress_domain 替换为集群中所有 Ingress Controller 的唯一域名。此变量需要是 DNS 名的子域 <clustername>.<domain>
    3
    您可以将 External 替换为 Internal,以使用内部 NLB。
  2. 在集群中创建资源:

    $ oc create -f ingresscontroller-aws-nlb.yaml
重要

在新 AWS 集群上配置 Ingress Controller NLB 之前,您必须完成 创建安装配置文件的步骤

28.5.2.5. 在新 AWS 集群上配置 Ingress Controller 网络负载平衡

您可在新集群中创建一个由 AWS Network Load Balancer(NLB)支持的 Ingress Controller。

先决条件

  • 创建 install-config.yaml 文件并完成对其所做的任何修改。

流程

在新集群中,创建一个由 AWS NLB 支持的 Ingress Controller。

  1. 进入包含安装程序的目录并创建清单:

    $ ./openshift-install create manifests --dir <installation_directory> 1
    1
    对于 <installation_directory>,请指定含有集群的 install-config.yaml 文件的目录的名称。
  2. <installation_directory>/manifests/ 目录中创建一个名为 cluster-ingress-default-ingresscontroller.yaml 的文件:

    $ touch <installation_directory>/manifests/cluster-ingress-default-ingresscontroller.yaml 1
    1
    对于 <installation_directory>,请指定包含集群的 manifests/ 目录的目录名称。

    创建该文件后,几个网络配置文件位于 manifests/ 目录中,如下所示:

    $ ls <installation_directory>/manifests/cluster-ingress-default-ingresscontroller.yaml

    输出示例

    cluster-ingress-default-ingresscontroller.yaml

  3. 在编辑器中打开 cluster-ingress-default-ingresscontroller.yaml 文件,并输入描述您想要的 Operator 配置的自定义资源(CR):

    apiVersion: operator.openshift.io/v1
    kind: IngressController
    metadata:
      creationTimestamp: null
      name: default
      namespace: openshift-ingress-operator
    spec:
      endpointPublishingStrategy:
        loadBalancer:
          scope: External
          providerParameters:
            type: AWS
            aws:
              type: NLB
        type: LoadBalancerService
  4. 保存 cluster-ingress-default-ingresscontroller.yaml 文件并退出文本编辑器。
  5. 可选:备份 manifests/cluster-ingress-default-ingresscontroller.yaml 文件。创建集群时,安装程序会删除 manifests/ 目录。

28.5.3. 其他资源