ResourceQuota Scope

This commit is contained in:
huanqing.shao
2019-10-20 23:33:25 +08:00
parent f628891183
commit fc26e5438a
11 changed files with 222 additions and 7 deletions

View File

@ -5,7 +5,7 @@ layout: LearningLayout
description: Kubernetes教程_默认情况下_容器在 Kubernetes 集群上运行时_不受计算资源的限制_使用Resourcequota集群管理员可以针对名称空间限定资源的使用情况
meta:
- name: keywords
content: Kubernetes
content: Kubernetes教程, LimitRange, Kubernetes Limit Range
---
# 概述

View File

@ -4,7 +4,7 @@ layout: LearningLayout
description: Kubernetes教程_本文讨论了如何在容器级别创建 LimitRange。假设有一个 Pod 包含 4个容器每个容器都定义了 spec.resource此时 LimitRanger 管理控制器在处理该 Pod 中的 4个容器是处理方式是不一样的。
meta:
- name: keywords
content: Kubernetes
content: Kubernetes教程, LimitRange, Kubernetes Limit Range
---
# 限定容器的计算资源

View File

@ -4,7 +4,7 @@ layout: LearningLayout
description: Kubernetes教程_本文讨论了如何使用LimitRange_在Pod级别限定资源的使用_下面是一个用于限定Pod资源使用的LimitRange对象。
meta:
- name: keywords
content: Kubernetes
content: Kubernetes教程, LimitRange, Kubernetes Limit Range
---
# 限定Pod的计算资源

View File

@ -4,7 +4,7 @@ layout: LearningLayout
description: Kubernetes教程_本文讨论了如何使用LimitRange在名称空间中限制Limits/Requests的比例_如果指定了LimitRange对象的spec.limits.maxLimitRequestRatio字段_名称空间中的Pod/容器的request和limit都不能为0_且limit除以request的结果必须小于或等于LimitRange的spec.limits.maxLimitRequestRatio
meta:
- name: keywords
content: Kubernetes
content: Kubernetes教程, LimitRange, Kubernetes Limit Range
---
# 限定 Limit/Request 比例

View File

@ -4,7 +4,7 @@ layout: LearningLayout
description: Kubernetes教程_本文讨论了如何使用LimitRange_名称空间中限制存储资源的使用_通过LimitRange对象_集群管理员可以限定名称空间中每个PersistentVolumeClaim存储卷声明可以使用的最小最大存储空间
meta:
- name: keywords
content: Kubernetes
content: Kubernetes教程, LimitRange, Kubernetes Limit Range
---
# 限定存储资源

View File

@ -4,7 +4,7 @@ layout: LearningLayout
description: Kubernetes教程_当多个用户或团队共享一个节点数量有限的集群时_如何在多个用户或团队之间分配集群的资源就会变得非常重要_Resource_quota的用途便在于此
meta:
- name: keywords
content: Kubernetes
content: Kubernetes 教程,Resource Quota,ResourceQuota
---
# 概述

View File

@ -0,0 +1,151 @@
---
vssueId: 144
layout: LearningLayout
description: Kubernetes教程_当多个用户或团队共享一个节点数量有限的集群时_如何在多个用户或团队之间分配集群的资源就会变得非常重要_Resource_quota的用途便在于此_本文探索了可以通过ResourceQuota限定名称空间资源配额时的作用域
meta:
- name: keywords
content: K8S 教程,Resource Quota,ResourceQuota
---
# 作用域
## 按Scope设定ResourceQuota
<AdSenseTitle >
> 参考文档:[Resource Quota](https://kubernetes.io/docs/concepts/policy/resource-quotas/)
当多个用户团队共享一个节点数量有限的集群时如何在多个用户团队之间分配集群的资源就会变得非常重要。Resource quota 的用途便在于此。本文主要探索通过 ResourceQuota 限定名称空间资源配额时的作用域。
每个 ResourceQuota 对象都可以绑定一组作用域,当 Kubernetes 对象与此 ResourceQuota 的作用域匹配在作用域中ResourceQuota 的限定才对该对象生效。
</AdSenseTitle>
| Scope作用域 | 描述 |
| --------------- | ------------------------------------------------------------ |
| Terminating | 包含所有 `.spec.activeDeadlineSeconds >= 0 ` 的 Pod |
| NotTerminating | 包含所有 `.spec.activeDeadlineSeconds is nil` 的Pod |
| BestEffort | 包含所有服务等级quality of service为 BestEffort 的 Pod |
| NotBestEffort | 包含所有服务等级quality of service为 NotBestEffort 的 Pod |
* 带有 `BestEffort` 作用域的 ResourceQuota 关注点为: `Pod`
* 带有 `Terminating`` NotTerminating``NotBestEffort` 的作用域关注点为:
* `cpu`
* `limits.cpu`
* `limits.memory`
* `memory`
* `pods`
* `requests.cpu`
* `requests.memory`
## 按PriorityClass设定ResourceQuota
**FEATURE STATE** `Kubernetes 1.12` <Badge type="warning">beta</Badge>
创建 Pod 时,可以指定 [priority](https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#pod-priority)。使用 ResourceQuota 的 `.spec.scopeSelector` 字段将 ResourceQuota 和 Pod 的 priority 关联,进而限定 Pod 的资源消耗。
<!--FIXME -->
只有当 ResourceQuota 的 `.spec.scopeSelector` 字段与 Pod 的 priorty 字段匹配时ResourceQuota 才生效。
下面的例子创建了一个通过 priority 限定特定 Pod 的 ResourceQuota 对象,该例子的工作方式如下:
* 假设集群中的 Pod 可以被指定三种 priority class `low``medium``high`
* 集群中为每个 Priority 都创建了一个 ResourceQuota 对象
定义 ResourceQuota 对象的文件如下所示:
<<< @/.vuepress/public/statics/learning/policy/rq-scope-quota.yaml
执行命令以创建 ResourceQuota
``` sh
kubectl create -f https://kuboard.cn/statics/learning/policy/rq-scope-quota.yaml
```
输出结果如下所示
```
resourcequota/pods-high created
resourcequota/pods-medium created
resourcequota/pods-low created
```
执行如下命令验证 quota 的使用为 `0`
```sh
kubectl describe quota
```
输出结果如下所示:
```
Name: pods-high
Namespace: default
Resource Used Hard
-------- ---- ----
cpu 0 1k
memory 0 200Gi
pods 0 10
Name: pods-low
Namespace: default
Resource Used Hard
-------- ---- ----
cpu 0 5
memory 0 10Gi
pods 0 10
Name: pods-medium
Namespace: default
Resource Used Hard
-------- ---- ----
cpu 0 10
memory 0 20Gi
pods 0 10
```
创建 “high” priority PodYAML 文件如下所示:
<<< @/.vuepress/public/statics/learning/policy/rq-scope-high-priority-pod.yaml
执行命令以创建
```sh
kubectl create -f https://kuboard.cn/statics/learning/policy/rq-scope-high-priority-pod.yaml
```
验证 "high" priority 对应的 ResourceQuota `pods-high` 的 `Used` 统计结果,可以发现 `pods-heigh` 的配额已经被使用,而其他两个的配额则没有被使用。
执行命令
``` sh
kubectl describe quota
```
输出结果如下所示:
```
Name: pods-high
Namespace: default
Resource Used Hard
-------- ---- ----
cpu 500m 1k
memory 10Gi 200Gi
pods 1 10
Name: pods-low
Namespace: default
Resource Used Hard
-------- ---- ----
cpu 0 5
memory 0 10Gi
pods 0 10
Name: pods-medium
Namespace: default
Resource Used Hard
-------- ---- ----
cpu 0 10
memory 0 20Gi
pods 0 10
```
`scopeSelector.matchExpressions.operator` 字段中可以使用如下几种取值
* In
* NotIn
* Exist
* DoesNotExist

View File

@ -4,7 +4,7 @@ layout: LearningLayout
description: Kubernetes教程_当多个用户或团队共享一个节点数量有限的集群时_如何在多个用户或团队之间分配集群的资源就会变得非常重要_Resource_quota的用途便在于此_本文探索了可以通过ResourceQuota限定的资源类型。
meta:
- name: keywords
content: Kubernetes
content: K8S 教程,Resource Quota,ResourceQuota
---
# 资源类型