$ oc create clusterquota for-user \
--project-annotation-selector openshift.io/requester=<user_name> \
--hard pods=10 \
--hard secrets=20
由ClusterResourceQuota
对象定义的多项目配额允许在多个项目之间共享配额。每个选定项目中使用的资源会被聚合,然后使用该聚合值来限制所有选定项目的资源。
本指南介绍集群管理员如何跨多个项目设置和管理资源配额。
不要在默认项目中运行工作负载或共享对默认项目的访问权限。默认项目保留用于运行核心集群组件。 以下默认项目被认为是高度特权的: |
创建配额时,您可以根据注释选择、标签选择或两者选择多个项目。
要根据注释选择项目,请运行以下命令:
$ 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个密钥。
同样,要根据标签选择项目,请运行此命令:
$ oc create clusterresourcequota for-name \(1)
--project-label-selector=name=frontend \(2)
--hard=pods=10 --hard=secrets=20
1 | clusterresourcequota 和clusterquota 是同一命令的别名。for-name 是ClusterResourceQuota 对象的名称。 |
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
资源执行此操作。
要查看应用于项目的配额,请运行:
$ 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