Help Center> Cloud Container Engine> Best Practices> Container> Setting the Container Network Bandwidth Limit
Updated on 2024-05-10 GMT+08:00

Setting the Container Network Bandwidth Limit

Application Scenarios

Containers on the same node share the host network bandwidth. Limiting the network bandwidth of containers can effectively prevent mutual interference between containers and improve container network stability.

Constraints

The following shows constraints on setting the rate limiting for inter-pod access:

Constraint Type

Tunnel network model

VPC network model

Cloud Native 2.0 Network Model

Supported versions

All versions

Clusters of v1.19.10 and later

Clusters of v1.19.10 and later

Supported runtime types

Only common containers

Supported pod types

Only non-HostNetwork pods

Supported scenarios

Inter-pod access, pods accessing nodes, and pods accessing services

Constraints

None

None

  • Pods access external cloud service CIDR blocks 100.64.0.0/10 and 214.0.0.0/8.
  • Traffic rate limiting of health check

Value range of rate limit

Only the rate limit in the unit of Mbit/s or Gbit/s is supported, for example, 100 Mbit/s and 1 Gbit/s. The minimum value is 1 Mbit/s and the maximum value is 4.29 Gbit/s.

Procedure

  1. Edit a YAML file for a workload.

    vi deployment.yaml

    Set the network bandwidth for the pod in spec.template.metadata.annotations to limit the network traffic of the container. For details about the network bandwidth limit fields, see Table 1.

    If the parameters are not specified, the network bandwidth is not limited by default.

    An example is as follows:

    apiVersion: apps/v1 
    kind: Deployment 
    metadata: 
      name: nginx 
    spec: 
      replicas: 1 
      selector: 
        matchLabels: 
          app: nginx 
      strategy: 
        type: RollingUpdate 
      template: 
        metadata: 
          labels: 
            app: nginx 
          annotations:
           # Ingress bandwidth
            kubernetes.io/ingress-bandwidth: 100M
           # Egress bandwidth
            kubernetes.io/egress-bandwidth: 1G
        spec: 
          containers: 
          - image: nginx  
            imagePullPolicy: Always 
            name: nginx 
          imagePullSecrets: 
          - name: default-secret
    Table 1 Fields for limiting the network bandwidth of pods

    Field

    Description

    Mandatory

    kubernetes.io/ingress-bandwidth

    Ingress bandwidth for a pod.

    Value range: 1k-1P. If this field is set to a value greater than 32 Gbit/s, the actual ingress bandwidth that a pod can use is 32 Gbit/s.

    No

    kubernetes.io/egress-bandwidth

    Egress bandwidth for a pod.

    Value range: 1k-1P. If this field is set to a value greater than 32 Gbit/s, the actual egress bandwidth that a pod can use is 32 Gbit/s.

    No

  2. Create a workload.

    kubectl create -f deployment.yaml

    Information similar to the following is displayed:

    deployment.apps/nginx created