你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Azure Red Hat OpenShift (ARO) 群集中配置群集范围的代理

本文介绍在 Azure Red Hat OpenShift 群集上启用群集范围的代理的过程。 此功能允许生产环境拒绝直接访问 Internet,而是提供 HTTP 或 HTTPS 代理。 本文详细介绍了 Azure Red Hat OpenShift 群集所需的特定配置步骤。 有关群集范围的代理功能如何适用于 OpenShift 容器平台的详细信息,请参阅 Red Hat 文档

配置群集范围的代理时,请务必了解以下影响:

  • 节点重启: 启用代理会导致节点以滚动方式重新启动,类似于群集更新。 这是必需的,因为它应用了新的计算机配置。
  • 服务中断: 为了避免在此过程中发生任何服务中断,请务必按所述准备 noProxy 列表。

重要

未能遵守本文中所述的说明可能会导致群集网络流量路由不当。 这可能会导致工作负载问题,例如镜像拉取失败。

群集范围的代理配置范围

  • OpenShift 工作负载: 本文中的说明仅适用于 OpenShift 工作负载。 代理应用程序工作负荷不适用于本文。
  • OpenShift 容器平台版本:群集范围的代理在 Azure Red Hat OpenShift 支持策略 中概述的 OpenShift 容器平台版本上受到支持。

按照本文中的说明进行操作,准备 noProxy 列表,以将中断降至最低,并在启用代理时确保平稳过渡。

先决条件和免责声明

  • 有关详细信息,请查看 OpenShift 文档 ,了解如何配置群集范围的代理
  • 代理服务器和证书:应已准备好代理服务器和证书。
  • Azure Red Hat OpenShift SRE 不支持代理服务器或证书。

概述

  1. 收集 noProxy 列表中所需的终端值以便使用。
  2. 使用收集的数据,启用群集级代理noProxy
  3. 验证noProxy列表和群集范围内的代理是否配置成功。

收集所需的数据 noProxy

  1. 运行以下命令验证群集范围的代理状态:

    oc get proxy cluster -o yaml
    

    spec字段和status字段应为空,显示它未启用。 如果它不为空,则以前可能已配置它。

    apiVersion: config.openshift.io/v1
    kind: Proxy
    metadata:
      creationTimestamp: "xxxx-xx-xxTxx:xx:xxZ"
      generation:
      name: cluster
      resourceVersion:
      uid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    spec:
      trustedCA:
        name: ""
    status: {}
    
  2. 请注意 IMDS IP: 169.254.169.254

  3. 如果不使用自定义 DNS,请注意 Azure DNS IP: 168.63.129.16

  4. 请注意 localhost 和服务域名:

    • localhost
    • 127.0.0.1
    • .svc
    • .cluster.local
  5. 通过运行以下命令来检索gatewayDomains

    oc get cluster cluster -o jsonpath='{.spec.gatewayDomains}'
    

    请参阅以下示例输出:

    [
        "agentimagestorews01.blob.core.windows.net",
        "agentimagestorecus01.blob.core.windows.net",
        "agentimagestoreeus01.blob.core.windows.net",
        "agentimagestoreeus01.blob.core.windows.net",
        "agentimagestoreeas01.blob.core.windows.net",
        "eastus-shared.prod.warm.ingest.monitor.core.windows.net",
        "...", // Many other endpoints
    ]
    
  6. 获取群集域名网址。

    为 API 和应用程序域创建特定于群集的 URL。

    a。 运行以下命令获取应用程序域:

    az aro show -n <CLUSTER_NAME> -g <RESOURCE_GROUP_NAME> --query "consoleProfile.url" -o tsv
    

    请参阅以下示例输出:

    https://console-openshift-console.apps.xxxxxxxx.westus2.aroapp.io/
    

    只保留以.apps.xxxxxxxx开头的部分供noProxy列表使用。 请勿包含尾随“/”。

    请参阅以下示例:

    .apps.xxxxxxxx.westus2.aroapp.io
    

    b. 获取 API 域。

    使用上一命令的输出,将 URL 中的 `.apps` 替换为 `api` 和 `api-int`,以获取 `noProxy` 列表的 API 域。

    请参阅以下示例:

    api.xxxxxxxx.westus2.aroapp.io
    api-int.xxxxxxxx.westus2.aroapp.io
    
  7. 获取 CIDR 范围列表。

    a。 运行以下命令从工作者配置文件子网中获取addressPrefix

    SUBNET_ID=$(az aro show -n <CLUSTER_NAME> -g <RESOURCE_GROUP_NAME> --query "workerProfiles[].subnetId" -o tsv)
    az network vnet subnet show --ids "$SUBNET_ID" --query "addressPrefix || [].addressPrefix" -o tsv
    

    示例输出:

    10.0.1.0/24
    

    b. 通过运行以下命令从主配置文件子网获取addressPrefix

    SUBNET_ID=$(az aro show -n <CLUSTER_NAME> -g <RESOURCE_GROUP_NAME> --query "masterProfile.subnetId" -o tsv)
    az network vnet subnet show --ids "$SUBNET_ID" --query "addressPrefix" -o tsv
    

    示例输出:

    10.0.0.0/24
    

    选项c. 通过运行以下命令获取podCidr

    az aro show -n <CLUSTER_NAME> -g <RESOURCE_GROUP_NAME> --query "networkProfile.podCidr" -o tsv
    

    示例输出:

    10.128.0.0/14
    

    d。 通过运行以下命令获取serviceCidr

    az aro show -n <CLUSTER_NAME> -g <RESOURCE_GROUP_NAME> --query "networkProfile.serviceCidr" -o tsv
    

    示例输出:

    172.30.0.0/16
    
  8. 将收集的数据合并到 noProxy 列表中,该列表将用于更新下一部分中的代理群集对象。

启用集群范围的代理

  1. user-ca-bundle 命名空间中创建 openshift-config configmap 以使用正确的证书。

    a。 创建一个名为user-ca-bundle.yaml的文件,内容如下,并提供您的 PEM 编码证书的值:

    apiVersion: v1
    data:
      ca-bundle.crt: |
        <MY_PEM_ENCODED_CERTS>
    kind: ConfigMap
    metadata:
      name: user-ca-bundle
      namespace: openshift-config
    
    • data.ca-bundle.crt:此数据密钥必须命名为 ca-bundle.crt
    • data.ca-bundle.crt | <MY_PEM_ENCODED_CERTS>:用于对代理标识证书进行签名的一个或多个 PEM 编码的 X.509 证书。
    • metadata.name:从代理对象引用的配置映射名称。
    • metadata.namespace:配置映射必须在openshift-config命名空间中。

    b. 运行以下命令创建 ConfigMap:

    oc create -f user-ca-bundle.yaml
    

    选项c. 运行以下命令确认创建 user-ca-bundle ConfigMap:

    oc get cm -n openshift-config user-ca-bundle -o yaml
    

    请参阅以下示例输出:

    apiVersion: v1
    data:
      ca-bundle.crt: |
         -----BEGIN CERTIFICATE-----
         <CERTIFICATE_DATA>
        -----END CERTIFICATE-----
    kind: ConfigMap
    metadata:
      creationTimestamp: "xxxx-xx-xxTxx:xx:xxZ"
      name: user-ca-bundle
      namespace: openshift-config
      resourceVersion: "xxxxxx"
      uid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    
  2. 使用oc edit更新代理群集对象,然后使用之前收集的信息配置代理对象。

    a。 运行下面的命令:

    oc edit proxy/cluster
    

    更新或添加以下字段:

    • spec.httpProxy:用于在群集外部创建 HTTP 连接的代理 URL。 URL 方案必须为 http
    • spec.httpsProxy:用于在群集外部创建 HTTPS 连接的代理 URL。
    • spec.noProxy:这是在 收集上述 noProxy 步骤所需的数据 中获取的终结点的逗号分隔列表。
    • spec.trustedCA:对命名空间中的 openshift-config 配置映射的引用,其中包含代理 HTTPS 连接所需的其他 CA 证书。 请注意,在此处引用配置映射之前,它必须已存在。 在这种情况下,这是上面创建的配置映射的名称,即 user-ca-bundle

    b. 运行以下命令确认配置:

    oc get proxy cluster -o yaml
    

    请参阅以下示例输出:

    apiVersion: config.openshift.io/v1
    kind: Proxy
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"config.openshift.io/v1","kind":"Proxy","metadata":{"annotations":{},"name":"cluster"},"spec":{"httpProxy":"http://10.0.0.15:3128","httpsProxy":"https://10.0.0.15:3129","noProxy":"agentimagestorecus01.blob.core.windows.net,agentimagestoreeus01.blob.core.windows.net,agentimagestorewus01.blob.core.windows.net,agentimagestoreweu01.blob.core.windows.net,agentimagestoreeas01.blob.core.windows.net,australiaeast-shared.prod.warm.ingest.monitor.core.windows.net,gcs.prod.monitoring.core.windows.net,gsm1130809042eh.servicebus.windows.net,gsm1130809042xt.blob.core.windows.net,gsm119650579eh.servicebus.windows.net,gsm119650579xt.blob.core.windows.net,gsm810972145eh.servicebus.windows.net,gsm810972145xt.blob.core.windows.net,maupdateaccount.blob.core.windows.net,maupdateaccount2.blob.core.windows.net,maupdateaccount3.blob.core.windows.net,maupdateaccount4.blob.core.windows.net,production.diagnostics.monitoring.core.windows.net,qos.prod.warm.ingest.monitor.core.windows.net,login.microsoftonline.com,management.azure.com,arosvc.azurecr.io,arosvc.australiaeast.data.azurecr.io,imageregistryvmxx7.blob.core.windows.net,.cluster.local,.svc,api-int.vlsi41ah.australiaeast.aroapp.io,localhost,10.0.0.0/8","trustedCA":{"name":"user-ca-bundle"}}}
      creationTimestamp: "xxxx-xx-xxTxx:xx:xxZ"
      generation: 17
      name: cluster
      resourceVersion: "xxxxxxx"
      uid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    spec:
      httpProxy: http://10.0.0.15:3128
      httpsProxy: https://10.0.0.15:3129
      noProxy: agentimagestorecus01.blob.core.windows.net,agentimagestoreeus01.blob.core.windows.net,agentimagestorewus01.blob.core.windows.net,agentimagestoreweu01.blob.core.windows.net,agentimagestoreeas01.blob.core.windows.net,australiaeast-shared.prod.warm.ingest.monitor.core.windows.net,gcs.prod.monitoring.core.windows.net,gsm1130809042eh.servicebus.windows.net,gsm1130809042xt.blob.core.windows.net,gsm119650579eh.servicebus.windows.net,gsm119650579xt.blob.core.windows.net,gsm810972145eh.servicebus.windows.net,gsm810972145xt.blob.core.windows.net,maupdateaccount.blob.core.windows.net,maupdateaccount2.blob.core.windows.net,maupdateaccount3.blob.core.windows.net,maupdateaccount4.blob.core.windows.net,production.diagnostics.monitoring.core.windows.net,qos.prod.warm.ingest.monitor.core.windows.net,login.microsoftonline.com,management.azure.com,arosvc.azurecr.io,arosvc.australiaeast.data.azurecr.io,imageregistryvmxx7.blob.core.windows.net,.cluster.local,.svc,api-int.vlsi41ah.australiaeast.aroapp.io,localhost,10.0.0.0/8
      trustedCA:
        name: user-ca-bundle
    status:
      httpProxy: http://10.0.0.15:3128
      httpsProxy: https://10.0.0.15:3129
      noProxy: .cluster.local,.svc,10.0.0.0/8,10.128.0.0/14,127.0.0.0/8,127.0.0.1,169.254.169.254,172.30.0.0/16,agentimagestorecus01.blob.core.windows.net,agentimagestoreeas01.blob.core.windows.net,agentimagestoreeus01.blob.core.windows.net,agentimagestoreweu01.blob.core.windows.net,agentimagestorewus01.blob.core.windows.net,api-int.vlsi41ah.australiaeast.aroapp.io,arosvc.australiaeast.data.azurecr.io,arosvc.azurecr.io,australiaeast-shared.prod.warm.ingest.monitor.core.windows.net,gcs.prod.monitoring.core.windows.net,gsm1130809042eh.servicebus.windows.net,gsm1130809042xt.blob.core.windows.net,gsm119650579eh.servicebus.windows.net,gsm119650579xt.blob.core.windows.net,gsm810972145eh.servicebus.windows.net,gsm810972145xt.blob.core.windows.net,imageregistryvmxx7.blob.core.windows.net,localhost,login.microsoftonline.com,management.azure.com,maupdateaccount.blob.core.windows.net,maupdateaccount2.blob.core.windows.net,maupdateaccount3.blob.core.windows.net,maupdateaccount4.blob.core.windows.net,production.diagnostics.monitoring.core.windows.net,qos.prod.warm.ingest.monitor.core.windows.net
    
  3. 等待将新的机器配置推送到所有节点,并让群集运算符报告健康状态。

    a。 运行以下命令确认节点运行状况:

    oc get nodes
    

    请参阅以下示例输出:

    NAME                                         STATUS   ROLES    AGE   VERSION
    mycluster-master-0                           Ready    master   10d   v1.xx.xx+xxxxxxx
    mycluster-master-1                           Ready    master   10d   v1.xx.xx+xxxxxxx
    mycluster-master-2                           Ready    master   10d   v1.xx.xx+xxxxxxx
    mycluster-worker-australiaeast1-mvzqr        Ready    worker   10d   v1.xx.xx+xxxxxxx
    mycluster-worker-australiaeast2-l9fgj        Ready    worker   10d   v1.xx.xx+xxxxxxx
    mycluster-worker-australiaeast3-pz9rw        Ready    worker   10d   v1.xx.xx+xxxxxxx
    

    b. 运行以下命令确认群集操作员的健康状况:

    oc get co
    

    请参阅以下示例输出:

    NAME                                VERSION        AVAILABLE   PROGRESSING   DEGRADED   SINCE   MESSAGE
    aro                                 vxxxxxxxx      True        False         False      10d
    authentication                      4.xx.xx        True        False         False      8m25s
    cloud-controller-manager            4.xx.xx        True        False         False      10d
    cloud-credential                    4.xx.xx        True        False         False      10d
    cluster-autoscaler                  4.xx.xx        True        False         False      10d
    ... (Many other components) ...
    storage                             4.xx.xx        True        False         False      10d
    

    注释

    如果需要 user-ca-bundle,它位于以下目录中(但此过程不需要):

    /etc/pki/ca-trust/source/anchors/openshift-config-user-ca-bundle.crt

验证 noProxy 配置

若要验证代理配置,请检查群集操作员的健康状况。 noProxy如果字段配置错误,则多个群集运算符可能进入状态Degraded: True。 这可能会导致各种问题,包括但不限于 ImagePullBack 错误、无效证书或常规连接问题。 此外,某些运算符可能由于类似的根本原因而处于 Progressing: True 状态。

  1. 运行以下命令检查群集作员的状态:

    oc get co
    
  2. 解释输出(正常状态):如果 noProxy 正确 配置了字段,输出应类似于以下示例:

    NAME                                       VERSION        AVAILABLE   PROGRESSING   DEGRADED   SINCE   MESSAGE
    aro                                        vxxxxxxxx.xx   True        False         False      15d
    authentication                             4.xx.xx        True        False         False      15d
    cloud-controller-manager                   4.xx.xx        True        False         False      15d
    cloud-credential                           4.xx.xx        True        False         False      15d
    

    注释

    群集运算符的数量和类型可能会有所不同。 提供的截断示例演示了 ARO 支持的运算符的正常状态。

  3. 解释输出(配置错误):如果 noProxy 字段 配置错误,输出可能类似于以下示例:

    NAME                         VERSION        AVAILABLE  PROGRESSING  DEGRADED  SINCE    MESSAGE
    aro                          vxxxxxxxx.xx   True       False        False     45h
    authentication               4.xx.xx        False      True         True      24h      OAuthServerRouteEndpointAccessibleControllerAvailable: Get "https://oauth-openshift.apps.mm6osebam6b03b9df3.eastus2euap.aroapp.io/healthz": Not Found
    control-plane-machine-set    4.xx.xx        True       False        False     46h      SyncLoopRefreshProgressing: Working toward version 4.15.35, 1 replicas available
    image-registry               4.xx.xx        True       True         False     45h      NodeCADaemonProgressing: The daemon set node-ca is deployed Progressing: The deployment has not completed
    ingress                      4.xx.xx        True       True         True      83m      The "default" ingress controller reports Degraded=True: DegradedConditions: One or more other status conditions indicate a degraded state: CanaryChecksSucceeding=False (CanaryChecksRepetitiveFailures: Canary route checks for the default ingress controller are failing)
    machine-config               4.xx.xx        False      False        True      43h      Cluster not available for [{operator 4.15.35}]: error during waitForControllerConfigToBeCompleted: [context deadline exceeded, controllerconfig is not completed: status for ControllerConfig machine-config-controller is being reported for 6, expecting it for 13]
    storage                      4.xx.xx        True       True         False     45h      AzureFileCSIDriverOperatorCRProgressing: AzureFileDriverControllerServiceControllerProgressing: Waiting for Deployment to deploy pods AzureFileCSIDriverOperatorCRProgressing: AzureFileDriverNodeServiceControllerProgressing: Waiting for DaemonSet to deploy node pods
    

    注释

    显示只是截断的示例输出。 其他群集运算符还可以报告由 Degraded: True 错误配置 noProxy导致的不同错误的状态。

删除群集范围的代理

有关删除群集范围的代理的信息,请参阅 Red Hat OpenShift 文档