Help Center> Cloud Container Engine> Best Practices> Container> Setting the Container Network Bandwidth Limit

Setting the Container Network Bandwidth Limit

Background

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.

Scenario

This function is supported on all types of workloads.

Constraints and Limitations

  • This function is available only to clusters of v1.13.10 and later and whose network model is tunnel network.
  • Clusters of v1.17 do not support this function.

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.

    The following is an example:

    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