The root file systems (RootFS) of all containers (including sandboxed containers) on a node that uses Sandboxed-Container share one disk. Some application containers may consume all of the disk I/O bandwidth. This may affect the performance of other application containers on the node. This topic provides an example of how to configure RootFS block I/O throttling on a pod. This allows you to avoid I/O contention among containers.

Prerequisites

Before you configure RootFS block I/O throttling on a pod, make sure that the following steps are complete:

Background information

RootFS block I/O throttling supports the following parameters:
  • read_bps: the maximum read speed in bytes per second.
  • write_bps: the maximum write speed in bytes per second.
  • read_iops: the maximum input/output operations per second (IOPS) of reads.
  • write_iops: the maximum IOPS of writes.
Notice This topic is applicable only to Sandboxed-Container V1 (V1.X.X). Sandboxed-Container V2 is not supported.

Parameters

To configure RootFS block I/O throttling on a pod, add a key-value pair to the annotations section in the pod configuration. Set the following parameters:
  • In the annotations section, set the key to io.kubernetes.container.blkio.
  • In the annotations section, set the value as shown in the following code block:
    '{
      "device_read_bps": [
        {
          "device": "rootfs",
          "value": "${VALUE}"
        }
      ],
      "device_write_bps": [
        {
          "device": "rootfs",
          "value": "${VALUE}"
        }
      ],
      "device_read_iops": [
        {
          "device": "rootfs",
          "value": "${VALUE}"
        }
      ],
      "device_write_iops": [
        {
          "device": "rootfs",
          "value": "${VALUE}"
        }
      ]
    }'
    Parameter Type Description
    device_read_bps Array The upper limit in bytes per second for read operations on a device.
    device_read_bps[].device String The absolute path to the device, for example, /dev/sda1. Only RootFS is supported.
    device_read_bps[].value String The value of the limit. Supported units: KB, MB, and GB. For example, a limit of 20 MB indicates that up to 20 MB of data can be read per second.
    device_write_bps Array The upper limit in bytes per second for write operations on a device.
    device_write_bps[].device String The absolute path to the device. For example, /dev/sda1. Only RootFS is supported.
    device_write_bps[].value String The value of the limit. Supported units: KB, MB, and GB. For example, a limit of 20 MB indicates that up to 20 MB of data can be written per second.
    device_read_iops Array The upper limit in operations per second for read operations on a device.
    device_read_iops[].device String The absolute path to the device, for example, /dev/sda1. Only RootFS is supported.
    device_read_iops[].value String The value of the limit. For example, a limit of 200 indicates that up to 200 read operations are allowed per second.
    device_write_iops Array The upper limit in operations per second for write operations on a device.
    device_write_iops[].device String The absolute path of the device, for example, /dev/sda1. Only RootFS is supported.
    device_write_iops[].value String The value of the limit. For example, a limit of 200 indicates that the maximum number of write operations per second is 200.

Examples

In the following example, a test application that run on a Deployment is created to show how to configure the following RootFS block I/O throttling settings: read speed limit: 20 MB/s, write speed limit: 20 MB/s, IOPS of reads: 200, and IOPS of writes: 300. Set the parameters in the following template:
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: iops-app
  name: iops-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: iops-app
  template:
    metadata:
      labels:
        app: iops-app
      annotations:
        io.kubernetes.container.blkio: '{"device_read_bps":[{"device":"rootfs","value":"20m"}],"device_write_bps":[{"device":"rootfs","value":"20m"}],"device_read_iops":[{"device":"rootfs","value":"200"}],"device_write_iops":[{"device":"rootfs","value":"300"}]}'
    spec:
      runtimeClassName: runv
      nodeSelector:
        alibabacloud.com/container-runtime: Sandboxed-Container.runv
      containers:
        - image: docker.io/centos:7
          command: ["/bin/sh","-c"]
          args: ["while(true);do /bin/sleep 10;done"]
          name: iops-app
          resources:
            requests:
              memory: "1Gi"
              cpu: 1
            limits:
              memory: "1Gi"
              cpu: 1
          volumeMounts:
            - name: host-time
              mountPath: /etc/localtime
      volumes:
        - name: host-time
          hostPath:
            path: /etc/localtime

Test the configurations

  1. Run the following commands to obtain the name of the created pod and log on to the pod:
    kubectl get pod
    kubectl exec -ti ${POD} /bin/sh
  2. Run the following commands to test the configurations.
    cd /
    dd if=/dev/zero of=test oflag=direct bs=1M count=10
    dd if=/dev/zero of=test oflag=direct bs=2M count=20

Result

Results

The output shows that the data write speed is about 20 MB/s, as shown in the preceding figure. This does not exceed the threshold as specified in the annotations section of the pod configurations.