Best practice for throttling block storage devices

Updated at:

Kubernetes does not natively throttle storage devices. In ACK, you can set per-pod IOPS and BPS limits on block storage such as cloud disks or LVM local disks to isolate I/O, manage storage resources, and stabilize performance. This topic uses cloud disks as an example.

Prerequisites

Before you begin:

  • Host OS is Alibaba Cloud Linux 2 or later.

  • ACK cluster runs Kubernetes 1.20 or later.

  • CSI plug-in is version 1.22 or later. See csi-provisioner.

Throttling parameters

Set these parameters in a StorageClass (dynamic provisioning) or in the volumeAttributes of a PersistentVolume (static provisioning):

Parameter Description Example value
readIOPS Max read IOPS per pod "100"
writeIOPS Max write IOPS per pod "10"
readBPS Max read throughput per pod "100k", "100m"
writeBPS Max write throughput per pod "100k", "100m"
Important

Cloud disk throttling settings cannot be changed after creation. StorageClass parameter changes apply only to newly created disks.

Throttle a cloud disk

Configure throttling for a cloud disk using dynamic or static volume provisioning.

Dynamic provisioning

  1. Create alicloud-disk-topology-essd.yaml with the following content:

    • parameters.readIOPS / parameters.writeIOPS: IOPS limits per pod.

    • parameters.readBPS / parameters.writeBPS: Throughput limits.

    • volumeBindingMode: WaitForFirstConsumer: Delays volume creation until a pod is scheduled to ensure correct zone placement.

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: alicloud-disk-topology-essd
    parameters:
      type: cloud_essd
      readIOPS: "100"
      writeIOPS: "10"
      readBPS: "100k"
      writeBPS: "100m"
    provisioner: diskplugin.csi.alibabacloud.com
    reclaimPolicy: Delete
    volumeBindingMode: WaitForFirstConsumer

    Key fields:

  2. Create the StorageClass:

    kubectl apply -f alicloud-disk-topology-essd.yaml
  3. Create nginx.yaml with the following content. The StatefulSet uses the StorageClass to provision an ESSD cloud disk.

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: web-csi-encrypt
    spec:
      selector:
        matchLabels:
          app: nginx
      serviceName: "nginx"
      podManagementPolicy: "Parallel"
      replicas: 1
      template:
        metadata:
          labels:
            app: nginx
        spec:
          hostNetwork: true
          containers:
          - name: nginx
            command:
            - sleep
            - "999999999"
            image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
            volumeMounts:
            - name: disk-csi
              mountPath: /data
      volumeClaimTemplates:
      - metadata:
          name: disk-csi
        spec:
          accessModes: [ "ReadWriteOnce" ]
          storageClassName: alicloud-disk-topology-essd
          resources:
            requests:
              storage: 80Gi
  4. Deploy the application:

    kubectl apply -f nginx.yaml
  5. Verify the throttling limits. See Verify throttling limits.

Static provisioning

  1. Create pv-static.yaml with the following content. Replace d-**** with your cloud disk ID.

    • volumeAttributes.readIOPS / volumeAttributes.readBPS: Throttling limits for this disk.

    • volumeHandle: The existing cloud disk ID.

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: d-****
    spec:
      accessModes:
      - ReadWriteMany
      capacity:
        storage: 80Gi
      csi:
        driver: diskplugin.csi.alibabacloud.com
        fsType: ext4
        volumeAttributes:
          app: nginx
          type: cloud_ssd
          readBPS: 100K
          readIOPS: "100"
        volumeHandle: d-****
      persistentVolumeReclaimPolicy: Retain
      volumeMode: Filesystem

    Key fields:

  2. Create the PersistentVolume (PV):

    kubectl apply -f pv-static.yaml
  3. Create pvc-static.yaml with the following content:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      labels:
        app: nginx
      name: disk-pvc
      namespace: default
    spec:
      accessModes:
      - ReadWriteMany
      resources:
        requests:
          storage: 80Gi
      volumeMode: Filesystem
      volumeName: d-****
  4. Create the PersistentVolumeClaim (PVC):

    kubectl apply -f pvc-static.yaml
  5. Create nginx.yaml with the following content. The Deployment uses the PVC to mount the statically provisioned disk.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: deploy-disk
      labels:
        app: nginx
    spec:
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
            ports:
            - containerPort: 80
            volumeMounts:
            - name: disk-pvc2
              mountPath: /data
          volumes:
            - name: disk-pvc2
              persistentVolumeClaim:
                claimName: disk-pvc
  6. Deploy the application:

    kubectl apply -f nginx.yaml
  7. Verify the throttling limits. See Verify throttling limits.

Verify throttling limits

Check the node's cgroup paths to verify that IOPS and BPS limits are applied.

Check the cgroup version

Log on to the node and run:

stat -fc %T /sys/fs/cgroup
  • If the output is cgroup2fs, the node uses cgroup V2.

  • Otherwise, the node uses cgroup V1.

Verify limits on cgroup V2

Construct the path with the pod UID and check io.max:

/sys/fs/cgroup/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod<UID>.slice/io.max

Verify limits on cgroup V1

Construct the paths with the pod UID and check these files:

Metric cgroup V1 path
readIOPS /sys/fs/cgroup/blkio/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod{pod_uid}.slice/blkio.throttle.read_iops_device
writeIOPS /sys/fs/cgroup/blkio/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod{pod_uid}.slice/blkio.throttle.write_iops_device
readBPS /sys/fs/cgroup/blkio/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod{pod_uid}.slice/blkio.throttle.read_bps_device
writeBPS /sys/fs/cgroup/blkio/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod{pod_uid}.slice/blkio.throttle.write_bps_device