Merge pull request #33779 from TinySong/task-5

[zh] sync tasks/administer-cluster/manage-resources
pull/33801/head
Kubernetes Prow Robot 2022-05-18 06:04:54 -07:00 committed by GitHub
commit 86a5120ea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 193 additions and 111 deletions

View File

@ -2,36 +2,53 @@
title: 为命名空间配置 CPU 最小和最大约束
content_type: task
weight: 40
description: >-
为命名空间定义一个有效的 CPU 资源限制范围,使得在该命名空间中所有新建 Pod 的 CPU 资源是在你所设置的范围内。
---
<!--
title: Configure Minimum and Maximum CPU Constraints for a Namespace
content_type: task
weight: 40
description: >-
Define a range of valid CPU resource limits for a namespace, so that every new Pod
in that namespace falls within the range you configure.
-->
<!-- overview -->
<!--
This page shows how to set minimum and maximum values for the CPU resources used by Containers
and Pods in a namespace. You specify minimum and maximum CPU values in a
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
This page shows how to set minimum and maximum values for the CPU resources used by containers
and Pods in a {{< glossary_tooltip text="namespace" term_id="namespace" >}}. You specify minimum
and maximum CPU values in a
[LimitRange](/docs/reference/kubernetes-api/policy-resources/limit-range-v1/)
object. If a Pod does not meet the constraints imposed by the LimitRange, it cannot be created
in the namespace.
-->
本页介绍如何为命名空间中容器和 Pod 使用的 CPU 资源设置最小和最大值。
本页介绍如何为{{< glossary_tooltip text="命名空间" term_id="namespace" >}}中的容器和 Pod
设置其所使用的 CPU 资源的最小和最大值。
你可以通过
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
对象声明 CPU 的最小和最大值. 如果 Pod 不能满足 LimitRange 的限制,它就不能在命名空间中创建。
[LimitRange](/docs/reference/kubernetes-api/policy-resources/limit-range-v1/)
对象声明 CPU 的最小和最大值.
如果 Pod 不能满足 LimitRange 的限制,就无法在该命名空间中被创建。
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
{{< include "task-tutorial-prereqs.md" >}}
<!--
Your cluster must have at least 1 CPU available for use to run the task examples.
You must have access to create namespaces in your cluster.
Each node in your cluster must have at least 1.0 CPU available for Pods.
See [meaning of CPU](/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)
to learn what Kubernetes means by “1 CPU”.
-->
你的集群中每个节点至少要有 1 个 CPU 可用才能运行本任务示例。
在你的集群里你必须要有创建命名空间的权限。
集群中的每个节点都必须至少有 1.0 个 CPU 可供 Pod 使用。
请阅读 [CPU 的含义](/zh/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)
理解 "1 CPU" 在 Kubernetes 中的含义。
<!-- steps -->
@ -52,11 +69,11 @@ kubectl create namespace constraints-cpu-example
<!--
## Create a LimitRange and a Pod
Here's the configuration file for a LimitRange:
Here's a manifest for an example {{< glossary_tooltip text="LimitRange" term_id="limitrange" >}}:
-->
## 创建 LimitRange 和 Pod
这里给出了 LimitRange 的配置文件
以下为 {{< glossary_tooltip text="LimitRange" term_id="limitrange" >}} 的示例清单
{{< codenew file="admin/resource/cpu-constraints.yaml" >}}
@ -100,24 +117,25 @@ limits:
```
<!--
Now whenever a Container is created in the constraints-cpu-example namespace, Kubernetes
performs these steps:
Now whenever you create a Pod in the constraints-cpu-example namespace (or some other client
of the Kubernetes API creates an equivalent Pod), Kubernetes performs these steps:
* If the Container does not specify its own CPU request and limit, assign the default
CPU request and limit to the Container.
* If any container in that Pod does not specify its own CPU request and limit, the control plane
assigns the default CPU request and limit to that container.
* Verify that the Container specifies a CPU request that is greater than or equal to 200 millicpu.
* Verify that every container in that Pod specifies a CPU request that is greater than or equal to 200 millicpu.
* Verify that the Container specifies a CPU limit that is less than or equal to 800 millicpu.
* Verify that every container in that Pod specifies a CPU limit that is less than or equal to 800 millicpu.
-->
现在不管什么时候在 constraints-cpu-example 命名空间中创建容器Kubernetes 都会执行下面这些步骤:
现在,每当你在 constraints-mem-example 命名空间中创建 Pod 时,或者某些其他的
Kubernetes API 客户端创建了等价的 Pod 时Kubernetes 就会执行下面的步骤:
* 如果容器没有声明自己的 CPU 请求和限制,将为容器指定默认 CPU 请求和限制。
* 如果 Pod 中的任何容器未声明自己的 CPU 请求和限制,控制面将为该容器设置默认的 CPU 请求和限制。
* 核查容器声明的 CPU 请求确保其大于或者等于 200 millicpu。
* 确保该 Pod 中的每个容器的 CPU 请求至少 200 millicpu。
* 核查容器声明的 CPU 限制确保其小于或者等于 800 millicpu。
* 确保该 Pod 中每个容器 CPU 请求不大于 800 millicpu。
<!--
When creating a `LimitRange` object, you can specify limits on huge-pages
@ -130,12 +148,12 @@ on these resources, the two values must be the same.
{{< /note >}}
<!--
Here's the configuration file for a Pod that has one Container. The Container manifest
Here's a manifest for a Pod that has one container. The container manifest
specifies a CPU request of 500 millicpu and a CPU limit of 800 millicpu. These satisfy the
minimum and maximum CPU constraints imposed by the LimitRange.
-->
这里给出了包含一个容器的 Pod 的配置文件
该容器声明了 500 millicpu 的 CPU 请求和 800 millicpu 的 CPU 限制
以下为某个仅包含一个容器的 Pod 的清单
该容器声明了 CPU 请求 500 millicpu 和 CPU 限制 800 millicpu
这些参数满足了 LimitRange 对象规定的 CPU 最小和最大限制。
{{< codenew file="admin/resource/cpu-constraints-pod.yaml" >}}
@ -143,16 +161,16 @@ minimum and maximum CPU constraints imposed by the LimitRange.
<!--
Create the Pod:
-->
创建Pod
创建 Pod
```shell
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod.yaml --namespace=constraints-cpu-example
```
<!--
Verify that the Pod's Container is running:
Verify that the Pod is running and that its container is healthy:
-->
确认一下 Pod 中的容器在运行
确认 Pod 正在运行,并且其容器处于健康状态
```shell
kubectl get pod constraints-cpu-demo --namespace=constraints-cpu-example
@ -168,10 +186,10 @@ kubectl get pod constraints-cpu-demo --output=yaml --namespace=constraints-cpu-e
```
<!--
The output shows that the Container has a CPU request of 500 millicpu and CPU limit
The output shows that the Pod's only container has a CPU request of 500 millicpu and CPU limit
of 800 millicpu. These satisfy the constraints imposed by the LimitRange.
-->
输出结果表明容器的 CPU 请求为 500 millicpuCPU 限制为 800 millicpu。
输出结果显示该 Pod 的容器的 CPU 请求为 500 millicpuCPU 限制为 800 millicpu。
这些参数满足 LimitRange 规定的限制范围。
```yaml
@ -214,10 +232,11 @@ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-2.ya
```
<!--
The output shows that the Pod does not get created, because the Container specifies a CPU limit that is
too large:
The output shows that the Pod does not get created, because it defines an unacceptable container.
That container is not acceptable because it specifies a CPU limit that is too large:
-->
输出结果表明 Pod 没有创建成功,因为容器声明的 CPU 限制太大了:
输出结果表明 Pod 没有创建成功,因为其中定义了一个无法被接受的容器。
该容器之所以无法被接受是因为其中设定了过高的 CPU 限制值:
```
Error from server (Forbidden): error when creating "examples/admin/resource/cpu-constraints-pod-2.yaml":
@ -227,12 +246,12 @@ pods "constraints-cpu-demo-2" is forbidden: maximum cpu usage per Container is 8
<!--
## Attempt to create a Pod that does not meet the minimum CPU request
Here's the configuration file for a Pod that has one Container. The Container specifies a
Here's a manifest for a Pod that has one container. The container specifies a
CPU request of 100 millicpu and a CPU limit of 800 millicpu.
-->
## 尝试创建一个不满足最小 CPU 请求的 Pod
这里给出了包含一个容器的 Pod 的配置文件。该容器声明了100 millicpu的 CPU 请求和800 millicpu的 CPU 限制
以下为某个只有一个容器的 Pod 的清单。该容器声明了 CPU 请求 100 millicpu 和 CPU 限制 800 millicpu
{{< codenew file="admin/resource/cpu-constraints-pod-3.yaml" >}}
@ -246,10 +265,12 @@ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-3.ya
```
<!--
The output shows that the Pod does not get created, because the Container specifies a CPU
request that is too small:
The output shows that the Pod does not get created, because it defines an unacceptable container.
That container is not acceptable because it specifies a CPU request that is lower than the
enforced minimum:
-->
输出结果显示 Pod 没有创建成功,因为容器声明的 CPU 请求太小了:
输出结果显示 Pod 没有创建成功,因为其中定义了一个无法被接受的容器。
该容器无法被接受的原因是其中所设置的 CPU 请求小于最小值的限制:
```
Error from server (Forbidden): error when creating "examples/admin/resource/cpu-constraints-pod-3.yaml":
@ -259,12 +280,12 @@ pods "constraints-cpu-demo-4" is forbidden: minimum cpu usage per Container is 2
<!--
## Create a Pod that does not specify any CPU request or limit
Here's the configuration file for a Pod that has one Container. The Container does not
specify a CPU request, and it does not specify a CPU limit.
Here's a manifest for a Pod that has one container. The container does not
specify a CPU request, nor does it specify a CPU limit.
-->
## 创建一个没有声明 CPU 请求和 CPU 限制的 Pod
这里给出了包含一个容器的 Pod 的配置文件。该容器没有设定 CPU 请求和 CPU 限制。
以下为一个只有一个容器的 Pod 的清单。该容器没有声明 CPU 请求,也没有声明 CPU 限制。
{{< codenew file="admin/resource/cpu-constraints-pod-4.yaml" >}}
@ -287,11 +308,14 @@ kubectl get pod constraints-cpu-demo-4 --namespace=constraints-cpu-example --out
```
<!--
The output shows that the Pod's Container has a CPU request of 800 millicpu and a CPU limit of 800 millicpu.
How did the Container get those values?
The output shows that the Pod's single container has a CPU request of 800 millicpu and a
CPU limit of 800 millicpu.
How did that container get those values?
-->
输出结果显示 Pod 的容器有个 800 millicpu 的 CPU 请求和 800 millicpu 的 CPU 限制。
容器是怎样得到那些值的呢?
输出结果显示 Pod 的唯一容器的 CPU 请求为 800 millicpuCPU 限制为 800 millicpu。
容器是怎样获得这些数值的呢?
```yaml
resources:
@ -302,26 +326,27 @@ resources:
```
<!--
Because your Container did not specify its own CPU request and limit, it was given the
[default CPU request and limit](/docs/tasks/administer-cluster/cpu-default-namespace/)
from the LimitRange.
Because that container did not specify its own CPU request and limit, the control plane
applied the
[default CPU request and limit](/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
from the LimitRange for this namespace.
-->
因为你的 Container 没有声明自己的 CPU 请求和限制LimitRange 给它指定了
[默认的 CPU 请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
因为这一容器没有声明自己的 CPU 请求和限制,
控制面会根据命名空间中配置 LimitRange
设置[默认的 CPU 请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)。
<!--
At this point, your Container might be running or it might not be running. Recall that a prerequisite
for this task is that your Nodes have at least 1 CPU. If each of your Nodes has only
1 CPU, then there might not be enough allocatable CPU on any Node to accommodate a request
of 800 millicpu. If you happen to be using Nodes with 2 CPU, then you probably have
enough CPU to accommodate the 800 millicpu request.
At this point, your Pod might be running or it might not be running. Recall that a prerequisite for
this task is that your Nodes must have at least 1 CPU available for use. If each of your Nodes has only 1 CPU,
then there might not be enough allocatable CPU on any Node to accommodate a request of 800 millicpu.
If you happen to be using Nodes with 2 CPU, then you probably have enough CPU to accommodate the 800 millicpu request.
Delete your Pod:
-->
此时,你的容器可能运行也可能没有运行
回想一下,本任务的先决条件是你的节点要有 1 个 CPU。
如果你的每个节点仅有 1 个 CPU那么可能没有任何一个节点可以满足 800 millicpu 的 CPU 请求。
如果你在用的节点恰好有两个 CPU那么你才可能有足够的 CPU 来满足 800 millicpu 的请求。
此时,你的 Pod 可能已经运行起来也可能没有运行起来
回想一下我们本次任务的先决条件是你的每个节点都至少有 1 CPU。
如果你的每个节点都只有 1 CPU那将没有一个节点拥有足够的可分配 CPU 来满足 800 millicpu 的请求。
如果你在用的节点恰好有 2 CPU那么有可能有足够的 CPU 来满足 800 millicpu 的请求。
```
kubectl delete pod constraints-cpu-demo-4 --namespace=constraints-cpu-example

View File

@ -107,8 +107,8 @@ file for the LimitRange, they were created automatically.
Now whenever you define a Pod within the constraints-mem-example namespace, Kubernetes
performs these steps:
* If any container in that Pod does not specify its own memory request and limit, assign
the default memory request and limit to that container.
* If any container in that Pod does not specify its own memory request and limit,
the control plane assig nthe default memory request and limit to that container.
* Verify that every container in that Pod requests at least 500 MiB of memory.
@ -121,7 +121,7 @@ minimum and maximum memory constraints imposed by the LimitRange.
-->
现在,每当在 constraints-mem-example 命名空间中创建 Pod 时Kubernetes 就会执行下面的步骤:
* 如果 Pod 中的任何容器未声明自己的内存请求和限制,将为该容器设置默认的内存请求和限制。
* 如果 Pod 中的任何容器未声明自己的内存请求和限制,控制面将为该容器设置默认的内存请求和限制。
* 确保该 Pod 中的每个容器的内存请求至少 500 MiB。

View File

@ -2,33 +2,43 @@
title: 为命名空间配置内存和 CPU 配额
content_type: task
weight: 50
description: >-
为命名空间定义总的 CPU 和内存资源限制。
---
<!--
title: Configure Memory and CPU Quotas for a Namespace
content_type: task
weight: 50
description: >-
Define overall memory and CPU resource limits for a namespace.
-->
<!-- overview -->
<!--
This page shows how to set quotas for the total amount memory and CPU that
can be used by all Containers running in a namespace. You specify quotas in a
[ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
can be used by all Pods running in a {{< glossary_tooltip text="namespace" term_id="namespace" >}}.
You specify quotas in a
[ResourceQuota](/docs/reference/kubernetes-api/policy-resources/resource-quota-v1/)
object.
-->
本文介绍怎样为命名空间设置容器可用的内存和 CPU 总量。你可以通过
[ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
本文介绍如何为{{< glossary_tooltip text="命名空间" term_id="namespace" >}}下运行的所有 Pod 设置总的内存和 CPU 配额。
你可以通过使用
[ResourceQuota](/docs/reference/kubernetes-api/policy-resources/resource-quota-v1/)
对象设置配额.
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
{{< include "task-tutorial-prereqs.md" >}}
<!--
You must have access to create namespaces in your cluster.
Each node in your cluster must have at least 1 GiB of memory.
-->
在你的集群里你必须要有创建命名空间的权限。
集群中每个节点至少有 1 GiB 的内存。
<!-- steps -->
@ -51,11 +61,11 @@ kubectl create namespace quota-mem-cpu-example
<!--
## Create a ResourceQuota
Here is the configuration file for a ResourceQuota object:
Here is a manifest for an example ResourceQuota:
-->
## 创建 ResourceQuota
这里给出一个 ResourceQuota 对象的配置文件
下面是 ResourceQuota 的示例清单
{{< codenew file="admin/resource/quota-mem-cpu.yaml" >}}
@ -80,28 +90,33 @@ kubectl get resourcequota mem-cpu-demo --namespace=quota-mem-cpu-example --outpu
<!--
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.
* For every Pod in the namespace, each container must have a memory request, memory limit, cpu request, and cpu limit.
* The memory request total for all Pods in that namespace must not exceed 1 GiB.
* The memory limit total for all Pods in that namespace must not exceed 2 GiB.
* The CPU request total for all Pods in that namespace must not exceed 1 cpu.
* The CPU limit total for all Pods in that namespace must not exceed 2 cpu.
See [meaning of CPU](/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)
to learn what Kubernetes means by “1 CPU”.
-->
ResourceQuota 在 quota-mem-cpu-example 命名空间中设置了如下要求:
* 每个容器必须有内存请求和限制,以及 CPU 请求和限制。
* 所有容器的内存请求总和不能超过1 GiB。
* 所有容器的内存限制总和不能超过2 GiB。
* 所有容器的 CPU 请求总和不能超过1 cpu。
* 所有容器的 CPU 限制总和不能超过2 cpu。
* 在该命名空间中的每个 Pod 的所有容器必须有内存请求和限制,以及 CPU 请求和限制。
* 在该命名空间中所有 Pod 的内存请求总和不能超过 1 GiB。
* 在该命名空间中所有 Pod 的内存限制总和不能超过 2 GiB。
* 在该命名空间中所有 Pod 的 CPU 请求总和不能超过 1 cpu。
* 在该命名空间中所有 Pod 的 CPU 限制总和不能超过 2 cpu。
请阅读 [CPU 的含义](/zh/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)
理解 "1 CPU" 在 Kubernetes 中的含义。
<!--
## Create a Pod
Here is the configuration file for a Pod:
Here is a manifest for an example Pod:
-->
## 创建 Pod
这里给出 Pod 的配置文件
以下是 Pod 的示例清单
{{< codenew file="admin/resource/quota-mem-cpu-pod.yaml" >}}
@ -115,11 +130,11 @@ kubectl apply -f https://k8s.io/examples/admin/resource/quota-mem-cpu-pod.yaml -
```
<!--
Verify that the Pod's Container is running:
Verify that the Pod is running and that its (only) container is healthy:
-->
检查下 Pod 中的容器在运行
确认 Pod 正在运行,并且其容器处于健康状态
```
```shell
kubectl get pod quota-mem-cpu-demo --namespace=quota-mem-cpu-example
```
@ -128,7 +143,7 @@ Once again, view detailed information about the ResourceQuota:
-->
再查看 ResourceQuota 的详情:
```
```shell
kubectl get resourcequota mem-cpu-demo --namespace=quota-mem-cpu-example --output=yaml
```
@ -153,27 +168,38 @@ status:
requests.memory: 600Mi
```
<!--
If you have the `jq` tool, you can also query (using [JSONPath](/docs/reference/kubectl/jsonpath/))
for just the `used` values, **and** pretty-print that that of the output. For example:
-->
如果有 `jq` 工具的话,你可以通过(使用 [JSONPath](/zh/docs/reference/kubectl/jsonpath/)
直接查询 `used` 字段的值,并且输出整齐的 JSON 格式。
```shell
kubectl get resourcequota mem-cpu-demo --namespace=quota-mem-cpu-example -o jsonpath='{ .status.used }' | jq .
```
<!--
## Attempt to create a second Pod
Here is the configuration file for a second Pod:
Here is a manifest for a second Pod:
-->
## 尝试创建第二个 Pod
这里给出了第二个 Pod 的配置文件:
以下为第二个 Pod 的清单
{{< codenew file="admin/resource/quota-mem-cpu-pod-2.yaml" >}}
<!--
In the configuration file, you can see that the Pod has a memory request of 700 MiB.
In the manifest, you can see that the Pod has a memory request of 700 MiB.
Notice that the sum of the used memory request and this new memory
request exceeds the memory request quota. 600 MiB + 700 MiB > 1 GiB.
request exceeds the memory request quota: 600 MiB + 700 MiB > 1 GiB.
Attempt to create the Pod:
-->
配置文件中,你可以看到 Pod 的内存请求为 700 MiB。
请注意新的内存请求与已经使用的内存请求只和超过了内存请求的配额。
在清单中,你可以看到 Pod 的内存请求为 700 MiB。
请注意新的内存请求与已经使用的内存请求之和超过了内存请求的配额:
600 MiB + 700 MiB > 1 GiB。
尝试创建 Pod
@ -198,19 +224,20 @@ requested: requests.memory=700Mi,used: requests.memory=600Mi, limited: requests.
## Discussion
As you have seen in this exercise, you can use a ResourceQuota to restrict
the memory request total for all Containers running in a namespace.
the memory request total for all Pods running in a namespace.
You can also restrict the totals for memory limit, cpu request, and cpu limit.
If you want to restrict individual Containers, instead of totals for all Containers, use a
[LimitRange](/docs/tasks/administer-cluster/memory-constraint-namespace/).
Instead of managing total resource use within a namespace, you might want to restrict
individual Pods, or the containers in those Pods. To achieve that kind of limiting, use a
[LimitRange](/docs/concepts/policy/limit-range/).
-->
## 讨论
如你在本练习中所见,你可以用 ResourceQuota 限制命名空间中所有容器的内存请求总量。
如你在本练习中所见,你可以用 ResourceQuota 限制命名空间中所有 Pod 的内存请求总量。
同样你也可以限制内存限制总量、CPU 请求总量、CPU 限制总量。
如果你想对单个容器而不是所有容器进行限制,就请使用
[LimitRange](/zh/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)。
除了可以管理命名空间资源使用的总和,如果你想限制单个 Pod或者限制这些 Pod 中的容器资源,
可以使用 [LimitRange](/zh/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/) 实现这类的功能
<!--
## Clean up
@ -257,6 +284,6 @@ kubectl delete namespace quota-mem-cpu-example
### 应用开发者参考
* [为容器和 Pod 分配内存资源](/zh/docs/tasks/configure-pod-container/assign-memory-resource/)
* [为容器和 Pod 分配CPU资源](/zh/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为容器和 Pod 分配 CPU 资源](/zh/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置服务质量](/zh/docs/tasks/configure-pod-container/quality-service-pod/)

View File

@ -2,24 +2,39 @@
title: 配置命名空间下 Pod 配额
content_type: task
weight: 60
description: >-
限制在命名空间中创建的 Pod 数量。
---
<!--
title: Configure a Pod Quota for a Namespace
content_type: task
weight: 60
description: >-
Restrict how many Pods you can create within a namespace.
-->
<!-- overview -->
<!--
This page shows how to set a quota for the total number of Pods that can run
in a namespace. You specify quotas in a
[ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
in a {{< glossary_tooltip text="Namespace" term_id="namespace" >}}. You specify quotas in a
[ResourceQuota](/docs/reference/kubernetes-api/policy-resources/resource-quota-v1/)
object.
-->
本文主要描述如何配置一个命名空间下可运行的 Pod 个数配额。
你可以使用
[ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
本文主要介绍如何在{{< glossary_tooltip text="命名空间" term_id="namespace" >}}中设置可运行 Pod 总数的配额。
你可以通过使用
[ResourceQuota](/zh/docs/reference/kubernetes-api/policy-resources/resource-quota-v1/)
对象来配置配额。
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
{{< include "task-tutorial-prereqs.md" >}}
<!--
You must have access to create namespaces in your cluster.
-->
在你的集群里你必须要有创建命名空间的权限。
<!-- steps -->
@ -40,11 +55,11 @@ kubectl create namespace quota-pod-example
<!--
## Create a ResourceQuota
Here is the configuration file for a ResourceQuota object:
Here is an example manifest for a ResourceQuota:
-->
## 创建 ResourceQuota
下面是一个 ResourceQuota 的配置文件
下面是 ResourceQuota 的示例清单
{{< codenew file="admin/resource/quota-pod.yaml" >}}
@ -83,18 +98,20 @@ status:
```
<!--
Here is the configuration file for a Deployment:
Here is an example manifest for a {{< glossary_tooltip term_id="deployment" >}}:
-->
下面是一个 Deployment 的配置文件
下面是一个 {{< glossary_tooltip term_id="deployment" >}} 的示例清单
{{< codenew file="admin/resource/quota-pod-deployment.yaml" >}}
<!--
In the configuration file, `replicas: 3` tells Kubernetes to attempt to create three Pods, all running the same application.
In that manifest, `replicas: 3` tells Kubernetes to attempt to create three new Pods, all
running the same application.
Create the Deployment:
-->
在配置文件中,`replicas: 3` 告诉 Kubernetes 尝试创建三个 Pods且运行相同的应用。
在清单中,`replicas: 3` 告诉 Kubernetes 尝试创建三个 Pods
且运行相同的应用。
创建这个 Deployment
@ -113,7 +130,7 @@ kubectl get deployment pod-quota-demo --namespace=quota-pod-example --output=yam
<!--
The output shows that even though the Deployment specifies three replicas, only two
Pods were created because of the quota.
Pods were created because of the quota you defined earlier:
-->
从输出的信息我们可以看到,尽管尝试创建三个 Pod但是由于配额的限制只有两个 Pod 能被成功创建。
@ -125,11 +142,24 @@ spec:
status:
availableReplicas: 2
...
lastUpdateTime: 2017-07-07T20:57:05Z
lastUpdateTime: 2021-04-02T20:57:05Z
message: 'unable to create pods: pods "pod-quota-demo-1650323038-" is forbidden:
exceeded quota: pod-demo, requested: pods=1, used: pods=2, limited: pods=2'
```
<!--
### Choice of resource
In this task you have defined a ResourceQuota that limited the total number of Pods, but
you could also limit the total number of other kinds of object. For example, you
might decide to limit how many {{< glossary_tooltip text="CronJobs" term_id="cronjob" >}}
that can live in a single namespace.
-->
### 资源的选择
在此任务中,你定义了一个限制 Pod 总数的 ResourceQuota
你也可以限制其他类型对象的总数。例如,
你可以限制在一个命名空间中可以创建的 {{< glossary_tooltip text="CronJobs" term_id="cronjob" >}} 的数量。
<!--
## Clean up