Run DPDK-based applications

更新时间:
复制 MD 格式

DPDK (Data Plane Development Kit) is a high-performance toolkit for developing network data plane applications. It is commonly used in scenarios that require low latency and high throughput. This topic describes how to run DPDK applications in an ACK cluster.

Step 1: Create a node pool that supports DPDK applications

You can create and configure a node pool that can run DPDK applications in the console.

1. Configure container networking at the node pool level

DPDK applications must run in Terway exclusive ENI mode. For configuration steps, see Configure exclusive ENI network mode for a node pool.

2. Enable DPDK dependencies for the node pool

To fully leverage DPDK's high-performance capabilities, configure VFIO drivers and HugePages before adding nodes to the cluster or starting DPDK applications.

  • VFIO driver: Allows applications to access physical network cards directly, which reduces latency.

  • HugePages: Reduces page table switching overhead and improves memory access efficiency.

On the node pool creation or edit page, click the Advanced Options (Optional) section. Then, in the User Data section, add the following script to complete the required configuration. For detailed steps, see Create and manage node pools.

# Enable VFIO driver
rmmod vfio-pci vfio_iommu_type1 vfio || true
modprobe vfio enable_unsafe_noiommu_mode=1
echo 1 > /sys/module/vfio/parameters/enable_unsafe_noiommu_mode
modprobe vfio-pci
# Enable hugepages on the node
sysctl -w vm.nr_hugepages=1024
# Restart kubelet to report hugepage resources
systemctl restart kubelet

Step 2: Use DPDK in a pod

1. Build a DPDK container image

Use the following Dockerfile example to build an official DPDK image.

FROM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3
ARG DPDK_VERSION=21.11.3
# dpdk dependency
RUN yum groupinstall -y 'Development Tools' && yum install -y python3 pciutils iproute && pip3 install meson ninja==v1.8.2 pyelftools
# dpdk build
RUN mkdir dpdk_build && cd dpdk_build && curl -OL http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz  \
    && tar -xvf dpdk-${DPDK_VERSION}.tar.xz  \
    && cd dpdk-stable-${DPDK_VERSION}  \
    && meson build && cd build && ninja && ninja install

2. Run the DPDK container image in a pod

To run the DPDK container image built earlier, configure the following key parameters for the pod.

  • Mount VFIO devices: Use a hostPath volume to mount the host's /dev directory to the container's /dev directory.

  • Request HugePages memory: Declare the HugePages and memory limits required by the DPDK application in the pod configuration.

  • Bind NIC drivers: Before the container starts, run mount -o remount,rw /sys/ && dpdk-devbind.py --force -b vfio-pci eth0 to bind the pod's NIC to the vfio-pci driver.

The following YAML example shows a pod that runs a DPDK application.

apiVersion: v1
kind: Pod
metadata:
  name: dpdk-test
spec:
  containers:
  - args:
    - "-c"
    - "mount -o remount,rw /sys/ && dpdk-devbind.py --force -b vfio-pci eth0 && dpdk-testpmd -- --forward-mode icmpecho"
    command:
    - bash
    tty: true
    image: registry.aliyuncs.com/acs-sample/dpdk-test:21.11.3
    imagePullPolicy: Always
    name: dpdk-test
    resources:
      limits:
        hugepages-2Mi: 1Gi
        memory: 2Gi
    securityContext:
      privileged: true
    volumeMounts:
    - name: host-dev
      mountPath: /dev
    - mountPath: /hugepages-2Mi
      name: hugepage-2mi
  volumes:
  - name: host-dev
    hostPath:
      path: /dev
  - name: hugepage-2mi
    emptyDir:
      medium: HugePages-2Mi