Best practice for throttling block storage devices
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" |
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
-
Create
alicloud-disk-topology-essd.yamlwith 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: WaitForFirstConsumerKey fields:
-
-
Create the StorageClass:
kubectl apply -f alicloud-disk-topology-essd.yaml -
Create
nginx.yamlwith 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 -
Deploy the application:
kubectl apply -f nginx.yaml -
Verify the throttling limits. See Verify throttling limits.
Static provisioning
-
Create
pv-static.yamlwith the following content. Replaced-****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: FilesystemKey fields:
-
-
Create the PersistentVolume (PV):
kubectl apply -f pv-static.yaml -
Create
pvc-static.yamlwith 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-**** -
Create the PersistentVolumeClaim (PVC):
kubectl apply -f pvc-static.yaml -
Create
nginx.yamlwith 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 -
Deploy the application:
kubectl apply -f nginx.yaml -
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 |