如何控制在特定k8s命名空间中运行的所有东西(在给定时刻)要使用的最大资源。 (最大内存,最大CPU)?
答案 0 :(得分:1)
这可以通过给定名称空间上的ResourceQuota完成。
来自docs:
由ResourceQuota对象定义的资源配额提供了限制每个命名空间的聚合资源消耗的约束。它可以按类型限制可在命名空间中创建的对象数量,以及该项目中的资源可能消耗的计算资源总量。
这样定义资源配额(来自k8s admin docs):
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文档
答案 1 :(得分:0)
定义每个命名空间的资源配额对象。 您可以设置每个名称空间的最大计算资源,还可以定义每个名称空间要部署的对象数。遵循以下示例
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/