【问题标题】:Controlling the maximum resources utilized by a k8s namespace控制 k8s 命名空间使用的最大资源
【发布时间】:2019-09-26 00:08:50
【问题描述】:

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

【问题讨论】:

    标签: kubernetes kubernetes-namespace


    【解决方案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 文档

    【讨论】:

    • 鼓励链接到外部资源,但请在链接周围添加上下文,以便您的其他用户了解它是什么以及为什么存在。始终引用重要链接中最相关的部分,以防目标站点无法访问或永久离线。请参阅:How to anwser
    【解决方案2】:

    为每个命名空间定义资源配额对象。 您可以设置每个命名空间的最大计算资源,还可以定义每个命名空间要部署的对象数量。按照以下示例进行操作

    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/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      • 2021-09-02
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 2019-07-28
      相关资源
      最近更新 更多