|Index|SUSE Telco Cloud 文档|电信功能配置|SR-IOV
适用范围 SUSE Telco Cloud 3.7

40 SR-IOV

SR-IOV(单根 I/O 虚拟化)允许单个物理设备(例如网络适配器)将其资源分散到多个 PCIe 硬件功能中。这使得各种应用程序能够直接访问资源。

我们为您提供了两种在集群中部署 SR-IOV 的不同方法:

在极少数需要两种解决方案的情况下(即对网络设备使用 Network Operator,对 vRAN 加速器使用 Device Plugin),您必须将它们部署到不同的 Kubernetes 名称空间中。这种分离对于防止两个部署之间的冲突至关重要。

40.1 选项 1:SR-IOV 网络设备插件 Daemonset 和 configMap

SR-IOV 网络设备插件 可发现并通告 Kubernetes 主机上的网络资源,例如 PCI 物理功能 (PF) 及其虚拟功能 (VF)。

  • 为设备插件准备配置映射 (config map)

我们需要创建一个定义 SR-IOV 资源池的配置映射。运行 lspci 命令以检索信息:

$ lspci | grep -i acc
07:00.0 Processing accelerators: Intel Corporation Device 57c2
07:00.1 Processing accelerators: Intel Corporation Device 57c3
07:00.2 Processing accelerators: Intel Corporation Device 57c3
07:00.3 Processing accelerators: Intel Corporation Device 57c3
07:00.4 Processing accelerators: Intel Corporation Device 57c3
07:00.5 Processing accelerators: Intel Corporation Device 57c3
07:00.6 Processing accelerators: Intel Corporation Device 57c3
07:00.7 Processing accelerators: Intel Corporation Device 57c3
07:01.0 Processing accelerators: Intel Corporation Device 57c3
07:01.1 Processing accelerators: Intel Corporation Device 57c3
07:01.2 Processing accelerators: Intel Corporation Device 57c3
07:01.3 Processing accelerators: Intel Corporation Device 57c3
07:01.4 Processing accelerators: Intel Corporation Device 57c3
07:01.5 Processing accelerators: Intel Corporation Device 57c3
07:01.6 Processing accelerators: Intel Corporation Device 57c3
07:01.7 Processing accelerators: Intel Corporation Device 57c3
07:02.0 Processing accelerators: Intel Corporation Device 57c3
0a:00.0 Processing accelerators: Intel Corporation Device 57c2

$ lspci | grep -i net
19:00.0 Ethernet controller: Broadcom Inc. and subsidiaries BCM57504 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb/200Gb Ethernet (rev 11)
19:00.1 Ethernet controller: Broadcom Inc. and subsidiaries BCM57504 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb/200Gb Ethernet (rev 11)
19:00.2 Ethernet controller: Broadcom Inc. and subsidiaries BCM57504 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb/200Gb Ethernet (rev 11)
19:00.3 Ethernet controller: Broadcom Inc. and subsidiaries BCM57504 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb/200Gb Ethernet (rev 11)
51:00.0 Ethernet controller: Intel Corporation Ethernet Controller E810-C for QSFP (rev 02)
51:00.1 Ethernet controller: Intel Corporation Ethernet Controller E810-C for QSFP (rev 02)
51:01.0 Ethernet controller: Intel Corporation Ethernet Adaptive Virtual Function (rev 02)
51:01.1 Ethernet controller: Intel Corporation Ethernet Adaptive Virtual Function (rev 02)
51:01.2 Ethernet controller: Intel Corporation Ethernet Adaptive Virtual Function (rev 02)
51:01.3 Ethernet controller: Intel Corporation Ethernet Adaptive Virtual Function (rev 02)
51:11.0 Ethernet controller: Intel Corporation Ethernet Adaptive Virtual Function (rev 02)
51:11.1 Ethernet controller: Intel Corporation Ethernet Adaptive Virtual Function (rev 02)
51:11.2 Ethernet controller: Intel Corporation Ethernet Adaptive Virtual Function (rev 02)
51:11.3 Ethernet controller: Intel Corporation Ethernet Adaptive Virtual Function (rev 02)

SR-IOV 设备插件使用包含 JSON 文件的 configMap 来定义 Kubernetes 应公开哪些硬件资源。此配置基于两个核心概念:selectors(用于硬件发现)和 resources(用于 Kubernetes 公开)。

resource 是 Pod 使用的命名实体(例如 rancher.io/intel_fec_5g)。资源可以定义为以下两种类型之一:

  • accelerator:用于 vRAN 加速卡(如 ACC100/vRAN Boost)。

  • netdevice:用于标准网络接口(NIC)。

您可以使用 selectors 来定义目标设备,以过滤节点上的硬件:

  • vendors:8086 (Intel)

  • devices:57c3 (FEC VF), 1889 (NIC VF)

  • drivers:vfio-pci

  • pfNames:eno16595np0(物理接口名称)

对于网卡,您还可以从物理功能中选择虚拟功能 (VF) 的子集:

  • pfNames:["eth1#1,2,3,4,5,6"] 或 [eth1#1-6]

为了允许 Pod 请求这些设备,每个资源都必须有一个名称,该名称由前缀和名称组成:

  • resourceName:pci_sriov_net_bh_dpdk

  • resourcePrefix:rancher.io

然后,Pod 将请求组合后的资源名称:rancher.io/pci_sriov_net_bh_dpdk。

注意
注意

本文档未列出所有可能的选择器。不同的资源类型使用不同的选择器集。有关详细信息,请参阅 SR-IOV 网络设备插件储存库。

下方的 ConfigMap 是一个创建三个资源的示例:一个用于 vRAN 加速卡 (FEC),两个用于两个不同的 NIC 端口。

对于 FEC 卡,您必须首先获取设备 ID 和 VFIO 词元。请遵循 第 42 章 “vRAN 加速 (Intel ACC100/VRB1/VRB2)” 章节中的说明以了解先决条件。

apiVersion: v1
kind: ConfigMap
metadata:
  name: sriovdp-config
  namespace: kube-system
data:
  config.json: |
    {
        "resourceList": [
            {
                "resourcePrefix": "rancher.io",
                "resourceName": "intel_fec_5g",
                "deviceType": "accelerator",
                "selectors": {
                    "vendors": ["8086"],
                    "devices": ["57c3"]
                },
                "additionalInfo": {
                      "*": {
                        "VFIO_TOKEN": "00112233-4455-6677-8899-aabbccddeeff"
                      }
                  }
            },
            {
                "resourcePrefix": "rancher.io",
                "resourceName": "intel_sriov_odu",
                "deviceType": "netdevice",
                "selectors": {
                    "vendors": ["8086"],
                    "devices": ["1889"],
                    "drivers": ["vfio-pci"],
                    "pfNames": ["eno16595np0"]
                }
            },
            {
                "resourcePrefix": "rancher.io",
                "resourceName": "intel_sriov_oru",
                "deviceType": "netdevice",
                "selectors": {
                    "vendors": ["8086"],
                    "devices": ["1889"],
                    "drivers": ["vfio-pci"],
                    "pfNames": ["eno16605np1"]
                }
            }
        ]
    }
  • 准备 daemonset 文件以部署设备插件。

该设备插件支持多种架构(arm、amd、ppc64le),因此可以通过为每种架构部署多个 daemonset,将同一个文件用于不同的架构。

apiVersion: v1
kind: ServiceAccount
metadata:
  name: sriov-device-plugin
  namespace: kube-system
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: kube-sriov-device-plugin-amd64
  namespace: kube-system
  labels:
    tier: node
    app: sriovdp
spec:
  selector:
    matchLabels:
      name: sriov-device-plugin
  template:
    metadata:
      labels:
        name: sriov-device-plugin
        tier: node
        app: sriovdp
    spec:
      hostNetwork: true
      nodeSelector:
        kubernetes.io/arch: amd64
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      serviceAccountName: sriov-device-plugin
      containers:
      - name: kube-sriovdp
        image: registry.suse.com/edge/3.7/sriov-network-device-plugin:v3.10.0
        imagePullPolicy: IfNotPresent
        args:
        - --log-dir=sriovdp
        - --log-level=10
        securityContext:
          privileged: true
        resources:
          requests:
            cpu: "250m"
            memory: "40Mi"
          limits:
            cpu: 1
            memory: "200Mi"
        volumeMounts:
        - name: devicesock
          mountPath: /var/lib/kubelet/
          readOnly: false
        - name: log
          mountPath: /var/log
        - name: config-volume
          mountPath: /etc/pcidp
        - name: device-info
          mountPath: /var/run/k8s.cni.cncf.io/devinfo/dp
      volumes:
        - name: devicesock
          hostPath:
            path: /var/lib/kubelet/
        - name: log
          hostPath:
            path: /var/log
        - name: device-info
          hostPath:
            path: /var/run/k8s.cni.cncf.io/devinfo/dp
            type: DirectoryOrCreate
        - name: config-volume
          configMap:
            name: sriovdp-config
            items:
            - key: config.json
              path: config.json
  • 应用 configMap 和 daemonset 后,设备插件将完成部署,接口将被发现并可供 Pod 使用。

    $ kubectl get pods -n kube-system | grep sriov
    kube-system  kube-sriov-device-plugin-amd64-twjfl  1/1  Running  0  2m
  • 验证所有节点,查看接口是否已被发现并可供 Pod 使用:

    $ kubectl get nodes -o json | jq '.items[] | {name: .metadata.name, allocatable: .status.allocatable}'
    {
      "name": "node1.suse.edge.com",
      "allocatable": {
          "cpu": "64",
          "ephemeral-storage": "256196109726",
          "hugepages-1Gi": "40Gi",
          "hugepages-2Mi": "0",
          "rancher.io/intel_fec_5g": "16",
          "rancher.io/intel_sriov_odu": "4",
          "rancher.io/intel_sriov_oru": "4",
          "memory": "221396384Ki",
          "pods": "110"
      }
    }
  • FEC 加速器的 resourceName 为 rancher.io/intel_fec_5g,且有 16 个 VF 可供使用。

  • NIC 卡的 resourceName 分别为 rancher.io/intel_sriov_odu 和 rancher.io/intel_sriov_oru。每个资源提供 4 个 VF。

重要
重要

如果 Kubernetes 节点中未检测到可分配资源的接口,则必须解决此问题。一个常见原因是 configMap 规范格式错误,因此最好检查 configMap 及其选择器。

40.2 选项 2(推荐):SR-IOV Network Operator

  • 如果尚未安装 Helm,请获取它:

$ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
  • 在 sriov-network-operator 命名空间中安装 SR-IOV 网络运营商:

helm install sriov-crd oci://registry.suse.com/edge/charts/sriov-crd -n sriov-network-operator
helm install sriov-network-operator oci://registry.suse.com/edge/charts/sriov-network-operator -n sriov-network-operator
  • 检查已部署的 CRD 和 Pod:

$ kubectl get crd
$ kubectl -n sriov-network-operator get pods
  • 检查 SR-IOV 标签是否已应用于节点。

当所有资源都在运行时,该标签会自动出现在您的节点中:

$ kubectl get nodes -oyaml | grep feature.node.kubernetes.io/network-sriov.capable

feature.node.kubernetes.io/network-sriov.capable: "true"
  • 查看 daemonset 以了解新的 sriov-network-config-daemon 和 sriov-rancher-nfd-worker 是否处于活动和就绪状态:

$ kubectl get daemonset -n sriov-network-operator
NAMESPACE             NAME                            DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR                                           AGE
sriov-network-operator   sriov-network-config-daemon     1         1         1       1            1           feature.node.kubernetes.io/network-sriov.capable=true   45m
sriov-network-operator   sriov-rancher-nfd-worker        1         1         1       1            1           <none>                                                  45m

几分钟后,节点将被检测到并完全配置 SR-IOV 功能。更新有时可能需要长达 10 分钟:

$ kubectl get sriovnetworknodestates -A
NAMESPACE             NAME     AGE
sriov-network-operator   xr11-2   83s
  • 检查接口是否已被检测到。

发现的接口应为网络设备的 PCI 地址。使用主机中的 lspci 命令检查此信息。

$ kubectl get sriovnetworknodestates -n sriov-network-operator -oyaml
apiVersion: v1
items:
- apiVersion: sriovnetwork.openshift.io/v1
  kind: SriovNetworkNodeState
  metadata:
    creationTimestamp: "2023-06-07T09:52:37Z"
    generation: 1
    name: xr11-2
    namespace: sriov-network-operator
    ownerReferences:
    - apiVersion: sriovnetwork.openshift.io/v1
      blockOwnerDeletion: true
      controller: true
      kind: SriovNetworkNodePolicy
      name: default
      uid: 80b72499-e26b-4072-a75c-f9a6218ec357
    resourceVersion: "356603"
    uid: e1f1654b-92b3-44d9-9f87-2571792cc1ad
  spec:
    dpConfigVersion: "356507"
  status:
    interfaces:
    - deviceID: "1592"
      driver: ice
      eSwitchMode: legacy
      linkType: ETH
      mac: 40:a6:b7:9b:35:f0
      mtu: 1500
      name: eno16595np0
      pciAddress: "0000:51:00.0"
      totalvfs: 128
      vendor: "8086"
    - deviceID: "1592"
      driver: ice
      eSwitchMode: legacy
      linkType: ETH
      mac: 40:a6:b7:9b:35:f1
      mtu: 1500
      name: eno16605np1
      pciAddress: "0000:51:00.1"
      totalvfs: 128
      vendor: "8086"
    syncStatus: Succeeded
kind: List
metadata:
  resourceVersion: ""
注意
注意

如果此处未检测到您的接口,请确保它存在于下一个配置映射中:

$ kubectl get cm supported-nic-ids -oyaml -n sriov-network-operator

如果未列出您的设备,请通过添加正确的值以进行发现来编辑配置映射。然后重启每个节点上的 sriov-network-config-daemon Pod 以使更新生效。

  • 创建 SriovNetworkNodePolicy 以配置 VFs

此策略创建资源 intelnicsDpdk,供 Pod 使用。它还将 vfio-pci 驱动程序绑定到提供的 PCI 设备,并创建 8 个 MTU 为 1500 的虚拟功能:

注意
注意

resourceName 字段不得包含任何特殊字符,并且在整个集群中必须是唯一的。 该示例使用 deviceType: vfio-pci,因为 DPDK 与 SR-IOV 结合使用。如果您不使用 DPDK,请配置 deviceType: netdevice(默认值)。

apiVersion: sriovnetwork.openshift.io/v1
kind: SriovNetworkNodePolicy
metadata:
  name: policy-dpdk
  namespace: sriov-network-operator
spec:
  nodeSelector:
    feature.node.kubernetes.io/network-sriov.capable: "true"
  resourceName: intelnicsDpdk
  deviceType: vfio-pci
  numVfs: 8
  mtu: 1500
  nicSelector:
    deviceID: "1592"
    vendor: "8086"
    rootDevices:
    - 0000:51:00.0
  • 验证所有节点上的配置:

使用预定义的 resourcePrefix rancher.io,应发现具有 8 个 VF 的资源 rancher.io/intelnicsDpdk。

$ kubectl get nodes -o jsonpath='{"items": [ { "name": @.metadata.name, "allocatable": @.status.allocatable } ]}' | jq
{
  "name": "node1.suse.edge.com",
  "allocatable": {
      "cpu": "64",
      "ephemeral-storage": "256196109726",
      "hugepages-1Gi": "60Gi",
      "hugepages-2Mi": "0",
      "rancher.io/intel_fec_5g": "16",
      "memory": "200424836Ki",
      "pods": "110",
      "rancher.io/intelnicsDpdk": "8"
  }
}
  • (可选)创建 sriovnetwork

此步骤为可选步骤,仅在自定义网络定义时需要。指定 resourceName 以绑定到先前创建的节点策略。

如果设置了 networkNamespace,则该网络将暴露给该命名空间中的 Pod。否则,该网络将在 Network Operator 的安装命名空间中可用。

apiVersion: sriovnetwork.openshift.io/v1
kind: SriovNetwork
metadata:
  name: network-dpdk
  namespace: sriov-network-operator        # where SRIOV Operator is installed
spec:
  ipam: |
    {
      "type": "host-local",
      "subnet": "192.168.0.0/24",
      "rangeStart": "192.168.0.20",
      "rangeEnd": "192.168.0.60",
      "routes": [{
        "dst": "0.0.0.0/0"
      }],
      "gateway": "192.168.0.1"
    }
  vlan: 500
  resourceName: intelnicsDpdk
  networkNamespace: default         # where workloads are deployed
  • 如果更新成功,则会在目标集群中创建 NetworkAttachmentDefinition (NAD)。

$ kubectl get net-attach-def -A -oyaml

apiVersion: v1
items:
- apiVersion: k8s.cni.cncf.io/v1
  kind: NetworkAttachmentDefinition
  metadata:
    annotations:
      k8s.v1.cni.cncf.io/resourceName: rancher.io/intelnicsDpdk
    creationTimestamp: "2023-06-08T11:22:27Z"
    generation: 1
    name: network-dpdk
    namespace: default
    resourceVersion: "13124"
    uid: df7c89f5-177c-4f30-ae72-7aef3294fb15
  spec:
    config: '{ "cniVersion":"0.4.0", "name":"network-dpdk","type":"sriov","vlan":500,"vlanQoS":0,"ipam":{"type":"host-local","subnet":"192.168.0.0/24","rangeStart":"192.168.0.10","rangeEnd":"192.168.0.60","routes":[{"dst":"0.0.0.0/0"}],"gateway":"192.168.0.1"}
      }'
kind: List
metadata:
  resourceVersion: ""

工作负载 Pod 可以使用 resourceName rancher.io/intelnicsDpdk 来使用网络接口的 VF。