6.3. 调度 NUMA 感知工作负载

运行对延迟敏感工作负载的集群通常具有性能配置集,以帮助最小化工作负载延迟并优化性能。NUMA 感知调度程序根据可用的节点 NUMA 资源部署工作负载,并遵循应用到节点的任何性能配置集设置。NUMA 感知部署和工作负载的性能配置集相结合,确保以最大化性能的方式调度工作负载。

6.3.1. 创建 NUMAResourcesOperator 自定义资源

安装 NUMA Resources Operator 后,创建 NUMAResourcesOperator 自定义资源 (CR) 来指示 NUMA Resources Operator 安装支持 NUMA 感知调度程序所需的所有集群基础架构,包括守护进程集和 API。

先决条件

  • 安装 OpenShift CLI(oc)。
  • 以具有 cluster-admin 特权的用户身份登录。
  • 安装 NUMA Resources Operator。

流程

  1. 创建 NUMAResourcesOperator 自定义资源:

    1. 将以下 YAML 保存到 nrop.yaml 文件中:

      apiVersion: nodetopology.openshift.io/v1
      kind: NUMAResourcesOperator
      metadata:
        name: numaresourcesoperator
      spec:
        nodeGroups:
        - machineConfigPoolSelector:
            matchLabels:
              pools.operator.machineconfiguration.openshift.io/worker: ""
    2. 运行以下命令来创建 NUMAResourcesOperator CR:

      $ oc create -f nrop.yaml

验证

  • 运行以下命令,验证 NUMA Resources Operator 是否已成功部署:

    $ oc get numaresourcesoperators.nodetopology.openshift.io

    输出示例

    NAME                    AGE
    numaresourcesoperator   10m

6.3.2. 部署 NUMA 感知辅助 pod 调度程序

安装 NUMA Resources Operator 后,执行以下操作来部署 NUMA 感知辅助 pod 调度程序:

  • 配置性能配置集。
  • 部署 NUMA 感知辅助调度程序。

先决条件

  • 安装 OpenShift CLI(oc)。
  • 以具有 cluster-admin 特权的用户身份登录。
  • 创建所需的机器配置池。
  • 安装 NUMA Resources Operator。

流程

  1. 创建 PerformanceProfile 自定义资源(CR):

    1. 将以下 YAML 保存到 nro-perfprof.yaml 文件中:

      apiVersion: performance.openshift.io/v2
      kind: PerformanceProfile
      metadata:
        name: perfprof-nrop
      spec:
        cpu: 1
          isolated: "4-51,56-103"
          reserved: "0,1,2,3,52,53,54,55"
        nodeSelector:
          node-role.kubernetes.io/worker: ""
        numa:
          topologyPolicy: single-numa-node
      1
      cpu.isolatedcpu.reserved 规格定义了隔离和保留 CPU 的范围。输入 CPU 配置的有效值。有关配置性能配置集的更多信息,请参阅附加资源部分
    2. 运行以下命令来创建 PerformanceProfile CR:

      $ oc create -f nro-perfprof.yaml

      输出示例

      performanceprofile.performance.openshift.io/perfprof-nrop created

  2. 创建 NUMAResourcesScheduler 自定义资源来部署 NUMA 感知自定义 pod 调度程序:

    1. 将以下 YAML 保存到 nro-scheduler.yaml 文件中:

      apiVersion: nodetopology.openshift.io/v1
      kind: NUMAResourcesScheduler
      metadata:
        name: numaresourcesscheduler
      spec:
        imageSpec: "registry.redhat.io/openshift4/noderesourcetopology-scheduler-container-rhel8:v4.13"
        cacheResyncPeriod: "5s" 1
      1
      为调度程序缓存同步输入间隔值(以秒为单位)。值 5s 通常用于大多数实现。
      注意
      • 启用 cacheResyncPeriod 规格,以帮助 NUMA Resource Operator 通过监控节点上的待处理资源,并在调度程序缓存中同步此信息,以帮助 NUMA Resource Operator 报告更准确的资源可用性。这也有助于减少 Topology Affinity Error 错误,因为未优化调度决策。网络负载越低的时间间隔。cacheResyncPeriod 规格默认禁用。
      • NUMAResourcesOperator CR 中的 podsFingerprinting 规格设置 Enabled 值是 cacheResyncPeriod 规格的实施要求。
    2. 运行以下命令来创建 NUMAResourcesScheduler CR:

      $ oc create -f nro-scheduler.yaml

验证

  1. 运行以下命令验证性能配置集是否已应用:

    $ oc describe performanceprofile <performance-profile-name>
  2. 运行以下命令验证所需资源是否已成功部署:

    $ oc get all -n openshift-numaresources

    输出示例

    NAME                                                    READY   STATUS    RESTARTS   AGE
    pod/numaresources-controller-manager-7575848485-bns4s   1/1     Running   0          13m
    pod/numaresourcesoperator-worker-dvj4n                  2/2     Running   0          16m
    pod/numaresourcesoperator-worker-lcg4t                  2/2     Running   0          16m
    pod/secondary-scheduler-56994cf6cf-7qf4q                1/1     Running   0          16m
    NAME                                          DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR                     AGE
    daemonset.apps/numaresourcesoperator-worker   2         2         2       2            2           node-role.kubernetes.io/worker=   16m
    NAME                                               READY   UP-TO-DATE   AVAILABLE   AGE
    deployment.apps/numaresources-controller-manager   1/1     1            1           13m
    deployment.apps/secondary-scheduler                1/1     1            1           16m
    NAME                                                          DESIRED   CURRENT   READY   AGE
    replicaset.apps/numaresources-controller-manager-7575848485   1         1         1       13m
    replicaset.apps/secondary-scheduler-56994cf6cf                1         1         1       16m

6.3.3. 使用 NUMA 感知调度程序调度工作负载

您可以使用 Deployment CR 将工作负载调度到 NUMA 感知调度程序,该 CR 指定处理工作负载的最低所需资源。

以下示例部署使用 NUMA 感知调度示例工作负载。

先决条件

  • 安装 OpenShift CLI(oc)。
  • 以具有 cluster-admin 特权的用户身份登录。
  • 安装 NUMA Resources Operator 并部署 NUMA 感知辅助调度程序。

流程

  1. 运行以下命令,获取集群中部署的 NUMA 感知调度程序名称:

    $ oc get numaresourcesschedulers.nodetopology.openshift.io numaresourcesscheduler -o json | jq '.status.schedulerName'

    输出示例

    topo-aware-scheduler

  2. 创建一个 Deployment CR,它使用名为 topo-aware-scheduler 的调度程序,例如:

    1. 将以下 YAML 保存到 nro-deployment.yaml 文件中:

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: numa-deployment-1
        namespace: openshift-numaresources
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: test
        template:
          metadata:
            labels:
              app: test
          spec:
            schedulerName: topo-aware-scheduler 1
            containers:
            - name: ctnr
              image: quay.io/openshifttest/hello-openshift:openshift
              imagePullPolicy: IfNotPresent
              resources:
                limits:
                  memory: "100Mi"
                  cpu: "10"
                requests:
                  memory: "100Mi"
                  cpu: "10"
            - name: ctnr2
              image: registry.access.redhat.com/rhel:latest
              imagePullPolicy: IfNotPresent
              command: ["/bin/sh", "-c"]
              args: [ "while true; do sleep 1h; done;" ]
              resources:
                limits:
                  memory: "100Mi"
                  cpu: "8"
                requests:
                  memory: "100Mi"
                  cpu: "8"
      1
      schedulerName 必须与集群中部署的 NUMA 感知调度程序的名称匹配,如 topo-aware-scheduler
    2. 运行以下命令来创建 Deployment CR:

      $ oc create -f nro-deployment.yaml

验证

  1. 验证部署是否成功:

    $ oc get pods -n openshift-numaresources

    输出示例

    NAME                                                READY   STATUS    RESTARTS   AGE
    numa-deployment-1-56954b7b46-pfgw8                  2/2     Running   0          129m
    numaresources-controller-manager-7575848485-bns4s   1/1     Running   0          15h
    numaresourcesoperator-worker-dvj4n                  2/2     Running   0          18h
    numaresourcesoperator-worker-lcg4t                  2/2     Running   0          16h
    secondary-scheduler-56994cf6cf-7qf4q                1/1     Running   0          18h

  2. 运行以下命令,验证 topo-aware-scheduler 是否在调度部署的 pod:

    $ oc describe pod numa-deployment-1-56954b7b46-pfgw8 -n openshift-numaresources

    输出示例

    Events:
      Type    Reason          Age   From                  Message
      ----    ------          ----  ----                  -------
      Normal  Scheduled       130m  topo-aware-scheduler  Successfully assigned openshift-numaresources/numa-deployment-1-56954b7b46-pfgw8 to compute-0.example.com

    注意

    请求的资源超过可用于调度的部署将失败,并显示 MinimumReplicasUnavailable 错误。当所需资源可用时,部署会成功。Pod 会一直处于 Pending 状态,直到所需资源可用。

  3. 验证是否为节点列出了预期的分配资源。

    1. 运行以下命令识别运行部署 pod 的节点,将 <namespace> 替换为您在 Deployment CR 中指定的命名空间:

      $ oc get pods -n <namespace> -o wide

      输出示例

      NAME                                 READY   STATUS    RESTARTS   AGE   IP            NODE     NOMINATED NODE   READINESS GATES
      numa-deployment-1-65684f8fcc-bw4bw   0/2     Running   0          82m   10.128.2.50   worker-0   <none>  <none>

    2. 运行以下命令,将 <node_name> 替换为运行部署 pod 的该节点的名称。

      $ oc describe noderesourcetopologies.topology.node.k8s.io <node_name>

      输出示例

      ...
      
      Zones:
        Costs:
          Name:   node-0
          Value:  10
          Name:   node-1
          Value:  21
        Name:     node-0
        Resources:
          Allocatable:  39
          Available:    21 1
          Capacity:     40
          Name:         cpu
          Allocatable:  6442450944
          Available:    6442450944
          Capacity:     6442450944
          Name:         hugepages-1Gi
          Allocatable:  134217728
          Available:    134217728
          Capacity:     134217728
          Name:         hugepages-2Mi
          Allocatable:  262415904768
          Available:    262206189568
          Capacity:     270146007040
          Name:         memory
        Type:           Node

      1
      由于已分配给有保证 pod 的资源,可用的容量会减少。

      通过保证 pod 使用的资源从 noderesourcetopologies.topology.node.k8s.io 中列出的可用节点资源中减去。

  4. 对具有 Best-effortBurstable 服务质量 (qosClass) 的pod 的资源分配不会反映在 noderesourcetopologies.topology.node.k8s.io 下的 NUMA 节点资源中。如果 pod 消耗的资源没有反映在节点资源计算中,请验证 pod 的 Guaranteed 具有 qosClass,且 CPU 请求是一个整数值,而不是十进制值。您可以运行以下命令来验证 pod 是否具有 GuaranteedqosClass

    $ oc get pod <pod_name> -n <pod_namespace> -o jsonpath="{ .status.qosClass }"

    输出示例

    Guaranteed