This topic describes how to set resource quotas and limits for a namespace through the Container Services console.

Prerequisites

Background information

By default, a running pod uses the CPU and memory resources of nodes without limit. That is, any pod can use the computing resources of the cluster without restraint. Therefore, pods of a namespace may deplete the cluster resources.

Namespaces can be used as virtual clusters to serve multiple users. Therefore, setting resource quotas for a namespace is regarded as a best practice.

For a namespace, you can set the quotas of resources, such as CPU, memory, and number of pods. For more information, see Resource quotas.

Procedure

  1. Log on to the Container Service console.
  2. In the left-side navigation pane under Kubernetes, choose Clusters > Namespace. Select the target cluster and click ResourceQuota and LimitRange on the right of the test namespace.


  3. In the displayed dialog box, set resource quotas and default resource limits.
    Note After setting CPU/memory quotas for a namespace, you must specify CPU/memory resource limits or set the default resource limits for the namespace when creating a pod. For more information, see Resource quotas.
    1. Set resource quotas for the namespace.


    2. To control the amount of resources consumed by containers, set resource limits and resource requests for containers in this namespace. For more information, see https://kubernetes.io//memory-default-namespace/.


  4. Connect to the Master node and then run the following commands to view the resources of the test namespace:
    
    #kubectl get limitrange,ResourceQuota -n test
    NAME AGE
    limitrange/limits 8m
    
    NAME AGE
    resourcequota/quota 8m
    
    
    # kubectl describe limitrange/limits resourcequota/quota -n test
    Name: limits
    Namespace: test
    Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio
    ---- -------- --- --- --------------- ------------- -----------------------
    Container cpu - - 100m 500m -
    Container memory - - 256Mi 512Mi -
    
    Name: quota
    Namespace: test
    Resource Used Hard
    -------- ---- ----
    configmaps 0 100
    limits.cpu 0 2
    limits.memory 0 4Gi
    persistentvolumeclaims 0 50
    pods 0 50
    requests.storage 0 1Ti
    secrets 1 10
    services 0 20
    services.loadbalancers 0 5