限制Blkio资源

  1. 配置轻量级虚拟机Blkio运行资源

    对轻量级虚拟机的BlkIio资源配置,安全容器使用—annotation com.github.containers.virtcontainers.blkio_cgroup配置轻量级虚拟机使用的块设备的blkio资源,该参数仅可配置在pause容器上:

    1. docker run -tid --runtime --network none --annotation io.kubernetes.docker.type=podsandbox --annotation com.github.containers.virtcontainers.blkio_cgroup=<blkio json格式字符串> <pause-image> <command>

    其中—annotation com.github.containers.virtcontainers.blkio_cgroup的取值要符合下面BlkioCgroup结构体的定义:

    1. // BlkioCgroup for Linux cgroup 'blkio' data exchange
    2. type BlkioCgroup struct {
    3. // Items specifies per cgroup values
    4. Items []BlockIOCgroupItem `json:"blkiocgroup,omitempty"`
    5. }
    6. type BlockIOCgroupItem struct {
    7. // Path represent path of blkio device
    8. Path string `json:"path,omitempty"`
    9. // Limits specifies the blkio type and value
    10. Limits []IOLimit `json:"limits,omitempty"`
    11. }
    12. type IOLimit struct {
    13. // Type specifies IO type
    14. Type string `json:"type,omitempty"`
    15. // Value specifies rate or weight value
    16. Value uint64 `json:"value,omitempty"`
    17. }

    IOLimit结构体中Type字段取值列表为:

    1. // BlkioThrottleReadBps is the key to fetch throttle_read_bps
    2. BlkioThrottleReadBps = "throttle_read_bps"
    3. // BlkioThrottleWriteBps is the key to fetch throttle_write_bps
    4. BlkioThrottleWriteBps = "throttle_write_bps"
    5. // BlkioThrottleReadIOPS is the key to fetch throttle_read_iops
    6. BlkioThrottleReadIOPS = "throttle_read_iops"
    7. // BlkioThrottleWriteIOPS is the key to fetch throttle_write_iops
    8. BlkioThrottleWriteIOPS = "throttle_write_iops"
    9. // BlkioWeight is the key to fetch blkio_weight
    10. BlkioWeight = "blkio_weight"
    11. // BlkioLeafWeight is the key to fetch blkio_leaf_weight
    12. BlkioLeafWeight = "blkio_leaf_weight"

    举例:

    1. docker run -tid --runtime kata-runtime --network none --annotation com.github.containers.virtcontainers.blkio_cgroup='{"blkiocgroup":[{"path":"/dev/sda","limits":[{"type":"throttle_read_bps","value":400},{"type":"throttle_write_bps","value":400},{"type":"throttle_read_iops","value":700},{"type":"throttle_write_iops","value":699}]},{"limits":[{"type":"blkio_weight","value":78}]}]}' rnd-dockerhub.huawei.com/official/pause

    上面命令表示对启动的安全容器所使用的/dev/sda磁盘进行blkio限流,分别将throttle_read_bps限速为400bps,throttle_write_bps限速为400bps,throttle_read_iops限速为700次/秒,throttle_write_iops限速为699次/秒,以及所在blkio cgroup组的权重值设置为78。