×

ClusterResourceQuota对象定义的多项目配额允许在多个项目之间共享配额。每个选定项目中使用的资源会被聚合,然后使用该聚合值来限制所有选定项目的资源。

本指南介绍集群管理员如何跨多个项目设置和管理资源配额。

不要在默认项目中运行工作负载或共享对默认项目的访问权限。默认项目保留用于运行核心集群组件。

以下默认项目被认为是高度特权的:defaultkube-publickube-systemopenshiftopenshift-infraopenshift-node以及其他具有openshift.io/run-level标签设置为01的系统创建的项目。依赖于准入插件的功能(例如Pod安全准入、安全上下文约束、集群资源配额和镜像引用解析)在高度特权的项目中不起作用。

在配额创建期间选择多个项目

创建配额时,您可以根据注释选择、标签选择或两者选择多个项目。

步骤
  1. 要根据注释选择项目,请运行以下命令:

    $ oc create clusterquota for-user \
         --project-annotation-selector openshift.io/requester=<user_name> \
         --hard pods=10 \
         --hard secrets=20

    这将创建以下ClusterResourceQuota对象:

    apiVersion: quota.openshift.io/v1
    kind: ClusterResourceQuota
    metadata:
      name: for-user
    spec:
      quota: (1)
        hard:
          pods: "10"
          secrets: "20"
      selector:
        annotations: (2)
          openshift.io/requester: <user_name>
        labels: null (3)
    status:
      namespaces: (4)
      - namespace: ns-one
        status:
          hard:
            pods: "10"
            secrets: "20"
          used:
            pods: "1"
            secrets: "9"
      total: (5)
        hard:
          pods: "10"
          secrets: "20"
        used:
          pods: "1"
          secrets: "9"
    1 将对选定项目强制执行的ResourceQuotaSpec对象。
    2 注释的简单键值选择器。
    3 可用于选择项目的标签选择器。
    4 描述每个选定项目中当前配额用量的每个命名空间映射。
    5 所有选定项目的聚合使用量。

    此多项目配额文档控制<user_name>使用默认项目请求端点请求的所有项目。您最多可使用10个Pod和20个密钥。

  2. 同样,要根据标签选择项目,请运行此命令:

    $  oc create clusterresourcequota for-name \(1)
        --project-label-selector=name=frontend \(2)
        --hard=pods=10 --hard=secrets=20
    1 clusterresourcequotaclusterquota是同一命令的别名。for-nameClusterResourceQuota对象的名称。
    2 要按标签选择项目,请使用格式--project-label-selector=key=value提供键值对。

    这将创建以下ClusterResourceQuota对象定义:

    apiVersion: quota.openshift.io/v1
    kind: ClusterResourceQuota
    metadata:
      creationTimestamp: null
      name: for-name
    spec:
      quota:
        hard:
          pods: "10"
          secrets: "20"
      selector:
        annotations: null
        labels:
          matchLabels:
            name: frontend

查看适用的集群资源配额

项目管理员不允许创建或修改限制其项目的多个项目的配额,但允许查看应用于其项目的多个项目的配额文档。项目管理员可以通过AppliedClusterResourceQuota资源执行此操作。

步骤
  1. 要查看应用于项目的配额,请运行:

    $ oc describe AppliedClusterResourceQuota
    示例输出
    Name:   for-user
    Namespace:  <none>
    Created:  19 hours ago
    Labels:   <none>
    Annotations:  <none>
    Label Selector: <null>
    AnnotationSelector: map[openshift.io/requester:<user-name>]
    Resource  Used  Hard
    --------  ----  ----
    pods        1     10
    secrets     9     20

选择粒度

由于在声明配额分配时需要考虑锁定问题,因此多项目配额选择的活动项目数量是一个重要的考虑因素。在一个多项目配额下选择超过100个项目可能会对这些项目的API服务器响应能力产生不利影响。