控制 k8s 命名空间使用的最大资源



如何控制在特定 k8s 命名空间中运行的所有东西(在给定时刻(使用的最大资源。(最大内存,最大 CPU(?

这可以通过给定命名空间上的 ResourceQuota 来完成。

从文档中:

资源配额(由 ResourceQuota 对象定义(提供限制每个命名空间聚合资源消耗的约束。它可以按类型限制可在命名空间中创建的对象数量,以及该项目中的资源可能消耗的计算资源总量。

资源配额是这样定义的(来自 k8s 管理文档(:

apiVersion: v1
kind: ResourceQuota
metadata:
name: mem-cpu-demo
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 2Gi

注意:此信息来自 k8s v1.16 文档

定义每个命名空间的资源配额对象。 您可以设置每个命名空间的最大计算资源数,还可以定义每个命名空间要部署的对象数。遵循以下示例

apiVersion: v1
kind: ResourceQuota
metadata:
name: mem-cpu-demo
namespace: quota-mem-cpu-example
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 2Gi
----
The ResourceQuota places these requirements on the quota-mem-cpu-example namespace:
Every Container must have a memory request, memory limit, cpu request, and cpu limit.
The memory request total for all Containers must not exceed 1 GiB.
The memory limit total for all Containers must not exceed 2 GiB.
The CPU request total for all Containers must not exceed 1 cpu.
The CPU limit total for all Containers must not exceed 2 cpu.
similarly define object quota
apiVersion: v1
kind: ResourceQuota
metadata:
name: object-quota-demo
namespace: quota-object-example
spec:
hard:
persistentvolumeclaims: "1"
services.loadbalancers: "2"
services.nodeports: "0"

Which implies that there can be at most one PersistentVolumeClaim, at most two Services of type LoadBalancer, and no Services of type NodePort.
reference: https://kubernetes.io/docs/tasks/administer-cluster/quota-api-object/

最新更新