|
| 1 | +--- |
| 2 | +title: Pod QoS 类 |
| 3 | +content_type: concept |
| 4 | +weight: 85 |
| 5 | +--- |
| 6 | +<!-- |
| 7 | +title: Pod Quality of Service Classes |
| 8 | +content_type: concept |
| 9 | +weight: 85 |
| 10 | +--> |
| 11 | + |
| 12 | +<!-- overview --> |
| 13 | + |
| 14 | +<!-- |
| 15 | +This page introduces _Quality of Service (QoS) classes_ in Kubernetes, and explains |
| 16 | +how Kubernetes assigns a QoS class to each Pods as a consequence of the resource |
| 17 | +constraints that you specify for the containers in that Pod. Kubernetes relies on this |
| 18 | +classification to make decisions about which Pods to evict when there are not enough |
| 19 | +available resources on a Node. |
| 20 | +--> |
| 21 | +本页介绍 Kubernetes 中的 **服务质量(Quality of Service,QoS)** 类, |
| 22 | +阐述 Kubernetes 如何根据为 Pod 中的容器指定的资源约束为每个 Pod 设置 QoS 类。 |
| 23 | +Kubernetes 依赖这种分类来决定当 Node 上没有足够可用资源时要驱逐哪些 Pod。 |
| 24 | + |
| 25 | +<!-- body --> |
| 26 | + |
| 27 | +<!-- |
| 28 | +## Quality of Service classes |
| 29 | +--> |
| 30 | +## QoS 类 {#qos-class} |
| 31 | + |
| 32 | +<!-- |
| 33 | +Kubernetes classifies the Pods that you run and allocates each Pod into a specific |
| 34 | +_quality of service (QoS) class_. Kubernetes uses that classification to influence how different |
| 35 | +pods are handled. Kubernetes does this classification based on the |
| 36 | +[resource requests](/docs/concepts/configuration/manage-resources-containers/) |
| 37 | +of the {{< glossary_tooltip text="Containers" term_id="container" >}} in that Pod, along with |
| 38 | +how those requests relate to resource limits. |
| 39 | +This is known as {{< glossary_tooltip text="Quality of Service" term_id="qos-class" >}} |
| 40 | +(QoS) class. Kubernetes assigns every Pod a QoS class based on the resource requests |
| 41 | +and limits of its component Containers. QoS classes are used by Kubernetes to decide |
| 42 | +which Pods to evict from a Node experiencing |
| 43 | +[Node Pressure](/docs/concepts/scheduling-eviction/node-pressure-eviction/). The possible |
| 44 | +QoS classes are `Guaranteed`, `Burstable`, and `BestEffort`. When a Node runs out of resources, |
| 45 | +Kubernetes will first evict `BestEffort` Pods running on that Node, followed by `Burstable` and |
| 46 | +finally `Guaranteed` Pods. When this eviction is due to resource pressure, only Pods exceeding |
| 47 | +resource requests are candidates for eviction. |
| 48 | +--> |
| 49 | +Kubernetes 对你运行的 Pod 进行分类,并将每个 Pod 分配到特定的 **QoS 类**中。 |
| 50 | +Kubernetes 使用这种分类来影响不同 Pod 被处理的方式。Kubernetes 基于 Pod |
| 51 | +中{{< glossary_tooltip text="容器" term_id="container" >}}的[资源请求](/zh-cn/docs/concepts/configuration/manage-resources-containers/)进行分类, |
| 52 | +同时确定这些请求如何与资源限制相关。 |
| 53 | +这称为{{< glossary_tooltip text="服务质量" term_id="qos-class" >}} (QoS) 类。 |
| 54 | +Kubernetes 基于每个 Pod 中容器的资源请求和限制为 Pod 设置 QoS 类。Kubernetes 使用 QoS |
| 55 | +类来决定从遇到[节点压力](/zh-cn/docs/concepts/scheduling-eviction/node-pressure-eviction/)的 |
| 56 | +Node 中驱逐哪些 Pod。可选的 QoS 类有 `Guaranteed`、`Burstable` 和 `BestEffort`。 |
| 57 | +当一个 Node 耗尽资源时,Kubernetes 将首先驱逐在该 Node 上运行的 `BestEffort` Pod, |
| 58 | +然后是 `Burstable` Pod,最后是 `Guaranteed` Pod。当这种驱逐是由于资源压力时, |
| 59 | +只有超出资源请求的 Pod 才是被驱逐的候选对象。 |
| 60 | + |
| 61 | +### Guaranteed |
| 62 | + |
| 63 | +<!-- |
| 64 | +Pods that are `Guaranteed` have the strictest resource limits and are least likely |
| 65 | +to face eviction. They are guaranteed not to be killed until they exceed their limits |
| 66 | +or there are no lower-priority Pods that can be preempted from the Node. They may |
| 67 | +not acquire resources beyond their specified limits. These Pods can also make |
| 68 | +use of exclusive CPUs using the |
| 69 | +[`static`](/docs/tasks/administer-cluster/cpu-management-policies/#static-policy) CPU management policy. |
| 70 | +--> |
| 71 | +`Guaranteed` Pod 具有最严格的资源限制,并且最不可能面临驱逐。 |
| 72 | +在这些 Pod 超过其自身的限制或者从 Node 上没有可以抢占的低优先级 Pod 之前, |
| 73 | +这些 Pod 保证不会被杀死。这些 Pod 不可以获得超出其指定 limit 的资源。这些 Pod 也可以使用 |
| 74 | +[`static`](/zh-cn/docs/tasks/administer-cluster/cpu-management-policies/#static-policy) |
| 75 | +CPU 管理策略来使用独占的 CPU。 |
| 76 | + |
| 77 | +<!-- |
| 78 | +#### Criteria |
| 79 | +
|
| 80 | +For a Pod to be given a QoS class of `Guaranteed`: |
| 81 | +--> |
| 82 | +#### 判据 |
| 83 | + |
| 84 | +Pod 被赋予 `Guaranteed` QoS 类的几个判据: |
| 85 | + |
| 86 | +<!-- |
| 87 | +* Every Container in the Pod must have a memory limit and a memory request. |
| 88 | +* For every Container in the Pod, the memory limit must equal the memory request. |
| 89 | +* Every Container in the Pod must have a CPU limit and a CPU request. |
| 90 | +* For every Container in the Pod, the CPU limit must equal the CPU request. |
| 91 | +--> |
| 92 | +* Pod 中的每个容器必须有内存 limit 和内存 request。 |
| 93 | +* 对于 Pod 中的每个容器,内存 limit 必须等于内存 request。 |
| 94 | +* Pod 中的每个容器必须有 CPU limit 和 CPU request。 |
| 95 | +* 对于 Pod 中的每个容器,CPU limit 必须等于 CPU request。 |
| 96 | + |
| 97 | +### Burstable |
| 98 | + |
| 99 | +<!-- |
| 100 | +Pods that are `Burstable` have some lower-bound resource guarantees based on the request, but |
| 101 | +do not require a specific limit. If a limit is not specified, it defaults to a |
| 102 | +limit equivalent to the capacity of the Node, which allows the Pods to flexibly increase |
| 103 | +their resources if resources are available. In the event of Pod eviction due to Node |
| 104 | +resource pressure, these Pods are evicted only after all `BestEffort` Pods are evicted. |
| 105 | +Because a `Burstable` Pod can include a Container that has no resource limits or requests, a Pod |
| 106 | +that is `Burstable` can try to use any amount of node resources. |
| 107 | +--> |
| 108 | +`Burstable` Pod 有一些基于 request 的资源下限保证,但不需要特定的 limit。 |
| 109 | +如果未指定 limit,则默认为其 limit 等于 Node 容量,这允许 Pod 在资源可用时灵活地增加其资源。 |
| 110 | +在由于 Node 资源压力导致 Pod 被驱逐的情况下,只有在所有 `BestEffort` Pod 被驱逐后 |
| 111 | +这些 Pod 才会被驱逐。因为 `Burstable` Pod 可以包括没有资源 limit 或资源 request 的容器, |
| 112 | +所以 `Burstable` Pod 可以尝试使用任意数量的节点资源。 |
| 113 | + |
| 114 | +<!-- |
| 115 | +#### Criteria |
| 116 | +
|
| 117 | +A Pod is given a QoS class of `Burstable` if: |
| 118 | +
|
| 119 | +* The Pod does not meet the criteria for QoS class `Guaranteed`. |
| 120 | +* At least one Container in the Pod has a memory or CPU request or limit. |
| 121 | +--> |
| 122 | +#### 判据 |
| 123 | + |
| 124 | +Pod 被赋予 `Burstable` QoS 类的几个判据: |
| 125 | + |
| 126 | +* Pod 不满足针对 QoS 类 `Guaranteed` 的判据。 |
| 127 | +* Pod 中至少一个容器有内存或 CPU request 或 limit。 |
| 128 | + |
| 129 | +### BestEffort |
| 130 | + |
| 131 | +<!-- |
| 132 | +Pods in the `BestEffort` QoS class can use node resources that aren't specifically assigned |
| 133 | +to Pods in other QoS classes. For example, if you have a node with 16 CPU cores available to the |
| 134 | +kubelet, and you assign 4 CPU cores to a `Guaranteed` Pod, then a Pod in the `BestEffort` |
| 135 | +QoS class can try to use any amount of the remaining 12 CPU cores. |
| 136 | +
|
| 137 | +The kubelet prefers to evict `BestEffort` Pods if the node comes under resource pressure. |
| 138 | +--> |
| 139 | +`BestEffort` QoS 类中的 Pod 可以使用未专门分配给其他 QoS 类中的 Pod 的节点资源。 |
| 140 | +例如若你有一个节点有 16 核 CPU 可供 kubelet 使用,并且你将 4 核 CPU 分配给一个 `Guaranteed` Pod, |
| 141 | +那么 `BestEffort` QoS 类中的 Pod 可以尝试任意使用剩余的 12 核 CPU。 |
| 142 | + |
| 143 | +如果节点遇到资源压力,kubelet 将优先驱逐 `BestEffort` Pod。 |
| 144 | + |
| 145 | +<!-- |
| 146 | +#### Criteria |
| 147 | +
|
| 148 | +A Pod has a QoS class of `BestEffort` if it doesn't meet the criteria for either `Guaranteed` |
| 149 | +or `Burstable`. In other words, a Pod is `BestEffort` only if none of the Containers in the Pod have a |
| 150 | +memory limit or a memory request, and none of the Containers in the Pod have a |
| 151 | +CPU limit or a CPU request. |
| 152 | +Containers in a Pod can request other resources (not CPU or memory) and still be classified as |
| 153 | +`BestEffort`. |
| 154 | +--> |
| 155 | +#### 判据 |
| 156 | + |
| 157 | +如果 Pod 不满足 `Guaranteed` 或 `Burstable` 的判据,则它的 QoS 类为 `BestEffort`。 |
| 158 | +换言之,只有当 Pod 中的所有容器没有内存 limit 或内存 request,也没有 CPU limit 或 |
| 159 | +CPU request 时,Pod 才是 `BestEffort`。Pod 中的容器可以请求(除 CPU 或内存之外的) |
| 160 | +其他资源并且仍然被归类为 `BestEffort`。 |
| 161 | + |
| 162 | +<!-- |
| 163 | +## Some behavior is independent of QoS class {#class-independent-behavior} |
| 164 | +
|
| 165 | +Certain behavior is independent of the QoS class assigned by Kubernetes. For example: |
| 166 | +--> |
| 167 | +## 某些行为独立于 QoS 类 {#class-independent-behavior} |
| 168 | + |
| 169 | +某些行为独立于 Kubernetes 分配的 QoS 类。例如: |
| 170 | + |
| 171 | +<!-- |
| 172 | +* Any Container exceeding a resource limit will be killed and restarted by the kubelet without |
| 173 | + affecting other Containers in that Pod. |
| 174 | +* If a Container exceeds its resource request and the node it runs on faces |
| 175 | + resource pressure, the Pod it is in becomes a candidate for [eviction](/docs/concepts/scheduling-eviction/node-pressure-eviction/). |
| 176 | + If this occurs, all Containers in the Pod will be terminated. Kubernetes may create a |
| 177 | + replacement Pod, usually on a different node. |
| 178 | +--> |
| 179 | +* 所有超过资源 limit 的容器都将被 kubelet 杀死并重启,而不会影响该 Pod 中的其他容器。 |
| 180 | +* 如果一个容器超出了自身的资源 request,且该容器运行的节点面临资源压力,则该容器所在的 Pod |
| 181 | + 就会成为被[驱逐](/zh-cn/docs/concepts/scheduling-eviction/node-pressure-eviction/)的候选对象。 |
| 182 | + 如果出现这种情况,Pod 中的所有容器都将被终止。Kubernetes 通常会在不同的节点上创建一个替代的 Pod。 |
| 183 | +<!-- |
| 184 | +* The resource request of a Pod is equal to the sum of the resource requests of |
| 185 | + its component Containers, and the resource limit of a Pod is equal to the sum of |
| 186 | + the resource limits of its component Containers. |
| 187 | +* The kube-scheduler does not consider QoS class when selecting which Pods to |
| 188 | + [preempt](/docs/concepts/scheduling-eviction/pod-priority-preemption/#preemption). |
| 189 | + Preemption can occur when a cluster does not have enough resources to run all the Pods |
| 190 | + you defined. |
| 191 | +--> |
| 192 | +* Pod 的资源 request 等于其成员容器的资源 request 之和,Pod 的资源 limit 等于其组成容器的资源 limit 之和。 |
| 193 | +* kube-scheduler 在选择要[抢占](/zh-cn/docs/concepts/scheduling-eviction/pod-priority-preemption/#preemption)的 |
| 194 | + Pod 时不考虑 QoS 类。当集群没有足够的资源来运行你所定义的所有 Pod 时,就会发生抢占。 |
| 195 | + |
| 196 | +## {{% heading "whatsnext" %}} |
| 197 | + |
| 198 | +<!-- |
| 199 | +* Learn about [resource management for Pods and Containers](/docs/concepts/configuration/manage-resources-containers/). |
| 200 | +* Learn about [Node-pressure eviction](/docs/concepts/scheduling-eviction/node-pressure-eviction/). |
| 201 | +* Learn about [Pod priority and preemption](/docs/concepts/scheduling-eviction/pod-priority-preemption/). |
| 202 | +* Learn about [Pod disruptions](/docs/concepts/workload/pods/disruptions/). |
| 203 | +* Learn how to [assign memory resources to containers and pods](/docs/tasks/configure-pod-container/assign-memory-resource/). |
| 204 | +* Learn how to [assign CPU resources to containers and pods](/docs/tasks/configure-pod-container/assign-cpu-resource/). |
| 205 | +* Learn how to [configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/). |
| 206 | +--> |
| 207 | +* 进一步了解[为 Pod 和容器管理资源](/zh-cn/docs/concepts/configuration/manage-resources-containers/)。 |
| 208 | +* 进一步了解[节点压力驱逐](/zh-cn/docs/concepts/scheduling-eviction/node-pressure-eviction/)。 |
| 209 | +* 进一步了解 [Pod 优先级和抢占](/zh-cn/docs/concepts/scheduling-eviction/pod-priority-preemption/)。 |
| 210 | +* 进一步了解 [Pod 干扰](/zh-cn/docs/concepts/workloads/pods/disruptions/)。 |
| 211 | +* 进一步了解如何[为容器和 Pod 分配内存资源](/zh-cn/docs/tasks/configure-pod-container/assign-memory-resource/)。 |
| 212 | +* 进一步了解如何[为容器和 Pod 分配 CPU 资源](/zh-cn/docs/tasks/configure-pod-container/assign-cpu-resource/)。 |
| 213 | +* 进一步了解如何[配置 Pod 的服务质量](/zh-cn/docs/tasks/configure-pod-container/quality-service-pod/)。 |
0 commit comments