0

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

4

2 回答 2

1

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

文档

由 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 文档

于 2019-09-26T00:13:22.960 回答
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/
于 2019-09-26T07:17:45.440 回答