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

OpenShift Container Platform 提供了从集群外部与集群中运行的服务进行通信的方法。此方法使用 Network Load Balancer(NLB),它会将客户端的 IP 地址转发到节点。您可以在新的或现有 AWS 集群上配置 NLB。

21.5.1. 将 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 有其他自定义,请确定您相应地修改该文件。

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

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

    等待 Ingress Controller 已被替换。预计中断的服务器停机时间。

21.5.2. 在现有 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 之前,您必须完成 创建安装配置文件的步骤

21.5.3. 在新 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/ 目录。

21.5.4. 其他资源