5.2. 跨越多个项目的资源配额

多项目配额由 ClusterResourceQuota 对象定义,允许在多个项目之间共享配额。对每个选定项目中使用的资源量进行合计,使用合计值来限制所有选定项目中的资源。

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

5.2.1. 在创建配额过程中选择多个项目

在创建配额时,您可以根据注解选择和/或标签选择来同时选择多个项目。

流程

  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 个 secret 的限制。

  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