[zh] Tidy up and fix links in tasks section (7/10)

This commit is contained in:
Qiming Teng
2020-08-15 11:30:50 +08:00
parent fcd8af988c
commit 30423d108f
12 changed files with 724 additions and 795 deletions
@@ -1,15 +1,13 @@
---
title: 为命名空间配置CPU最小和最大限制
title: 为命名空间配置 CPU 最小和最大约束
content_type: task
weight: 40
---
<!--
---
title: Configure Minimum and Maximum CPU Constraints for a Namespace
content_type: task
weight: 40
---
-->
<!-- overview -->
@@ -21,25 +19,19 @@ and Pods in a namespace. You specify minimum and maximum CPU values in a
object. If a Pod does not meet the constraints imposed by the LimitRange, it cannot be created
in the namespace.
-->
本章介绍命名空间中可以被容器和Pod使用的CPU资源的最小和最大值。你可以通过 [LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core) 对象声明 CPU 的最小和最大值. 如果 Pod 不能满足 LimitRange 的限制,它就不能在命名空间中创建。
本页介绍如何为命名空间中容器和 Pod 使用的 CPU 资源设置最小和最大值。
你可以通过
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
对象声明 CPU 的最小和最大值. 如果 Pod 不能满足 LimitRange 的限制,它就不能在命名空间中创建。
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!--
Each node in your cluster must have at least 1 CPU.
Your cluster must have at least 1 CPU available for use to run the task examples.
-->
你的集群中每个节点至少要有1个CPU。
你的集群中每个节点至少要有 1 个 CPU 可用才能运行本任务示例。
<!-- steps -->
@@ -49,7 +41,6 @@ Each node in your cluster must have at least 1 CPU.
Create a namespace so that the resources you create in this exercise are
isolated from the rest of your cluster.
-->
## 创建命名空间
创建一个命名空间,以便本练习中创建的资源和集群的其余资源相隔离。
@@ -63,7 +54,6 @@ kubectl create namespace constraints-cpu-example
Here's the configuration file for a LimitRange:
-->
## 创建 LimitRange 和 Pod
这里给出了 LimitRange 的配置文件:
@@ -73,17 +63,15 @@ Here's the configuration file for a LimitRange:
<!--
Create the LimitRange:
-->
创建 LimitRange:
```shell
kubectl create -f https://k8s.io/examples/admin/resource/cpu-constraints.yaml --namespace=constraints-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints.yaml --namespace=constraints-cpu-example
```
<!--
View detailed information about the LimitRange:
-->
查看 LimitRange 详情:
```shell
@@ -95,8 +83,8 @@ The output shows the minimum and maximum CPU constraints as expected. But
notice that even though you didn't specify default values in the configuration
file for the LimitRange, they were created automatically.
-->
输出结果显示 CPU 的最小和最大限制符合预期。但需要注意的是,尽管你在 LimitRange 的配置文件中你没有声明默认值,默认值也会被自动创建。
输出结果显示 CPU 的最小和最大限制符合预期。但需要注意的是,尽管你在 LimitRange
的配置文件中你没有声明默认值,默认值也会被自动创建。
```yaml
limits:
@@ -127,45 +115,43 @@ CPU request and limit to the Container.
* 如果容器没有声明自己的 CPU 请求和限制,将为容器指定默认 CPU 请求和限制。
* 核查容器声明的 CPU 请求确保其大于或者等于200 millicpu。
* 核查容器声明的 CPU 请求确保其大于或者等于 200 millicpu。
* 核查容器声明的 CPU 限制确保其小于或者等于800 millicpu。
* 核查容器声明的 CPU 限制确保其小于或者等于 800 millicpu。
{{< note >}} 当创建 LimitRange 对象时,你也可以声明 huge-page 和 GPU 的限制。当这些资源同时声明了 'default' 和 defaultRequest 参数时,两个参数值必须相同。 {{< /note >}}
<!--
When creating a `LimitRange` object, you can specify limits on huge-pages
or GPUs as well. However, when both `default` and `defaultRequest` are specified
on these resources, the two values must be the same.
-->
{{< note >}}
当创建 LimitRange 对象时,你也可以声明大页面和 GPU 的限制。
当这些资源同时声明了 'default' 和 'defaultRequest' 参数时,两个参数值必须相同。
{{< /note >}}
<!--
Here's the configuration file 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 限制。这些参数满足了 LimitRange 对象规定的 CPU 最小和最大限制。
这里给出了包含一个容器的 Pod 的配置文件。
该容器声明了 500 millicpu 的 CPU 请求和 800 millicpu 的 CPU 限制。
这些参数满足了 LimitRange 对象规定的 CPU 最小和最大限制。
{{< codenew file="admin/resource/cpu-constraints-pod.yaml" >}}
<!--
Create the Pod:
-->
创建Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/cpu-constraints-pod.yaml --namespace=constraints-cpu-example
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:
-->
确认一下 Pod 中的容器在运行:
```shell
@@ -175,7 +161,6 @@ kubectl get pod constraints-cpu-demo --namespace=constraints-cpu-example
<!--
View detailed information about the Pod:
-->
查看 Pod 的详情:
```shell
@@ -186,8 +171,8 @@ 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
of 800 millicpu. These satisfy the constraints imposed by the LimitRange.
-->
输出结果表明容器的 CPU 请求为500 millicpuCPU限制为800 millicpu。这些参数满足 LimitRange 规定的限制范围。
输出结果表明容器的 CPU 请求为 500 millicpuCPU 限制为 800 millicpu。
这些参数满足 LimitRange 规定的限制范围。
```yaml
resources:
@@ -200,7 +185,6 @@ resources:
<!--
## Delete the Pod
-->
## 删除 Pod
```shell
@@ -213,28 +197,26 @@ kubectl delete pod constraints-cpu-demo --namespace=constraints-cpu-example
Here's the configuration file for a Pod that has one Container. The Container specifies a
CPU request of 500 millicpu and a cpu limit of 1.5 cpu.
-->
## 尝试创建一个超过最大 CPU 限制的 Pod
这里给出了包含一个容器的 Pod 的配置文件。容器声明了500 millicpu的CPU请求和1.5 cpu的 CPU 限制。
这里给出了包含一个容器的 Pod 的配置文件。容器声明了 500 millicpu 的 CPU
请求和 1.5 CPU 的 CPU 限制。
{{< codenew file="admin/resource/cpu-constraints-pod-2.yaml" >}}
<!--
Attempt to create the Pod:
-->
尝试创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-2.yaml --namespace=constraints-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-2.yaml --namespace=constraints-cpu-example
```
<!--
The output shows that the Pod does not get created, because the Container specifies a CPU limit that is
too large:
-->
输出结果表明 Pod 没有创建成功,因为容器声明的 CPU 限制太大了:
```
@@ -248,7 +230,6 @@ pods "constraints-cpu-demo-2" is forbidden: maximum cpu usage per Container is 8
Here's the configuration file 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 限制。
@@ -258,18 +239,16 @@ CPU request of 100 millicpu and a CPU limit of 800 millicpu.
<!--
Attempt to create the Pod:
-->
尝试创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-3.yaml --namespace=constraints-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-3.yaml --namespace=constraints-cpu-example
```
<!--
The output shows that the Pod does not get created, because the Container specifies a CPU
request that is too small:
-->
输出结果显示 Pod 没有创建成功,因为容器声明的 CPU 请求太小了:
```
@@ -283,27 +262,24 @@ pods "constraints-cpu-demo-4" is forbidden: minimum cpu usage per Container is 2
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.
-->
## 创建一个没有声明 CPU 请求和 CPU 限制的 Pod
## 创建一个没有声明CPU请求和CPU限制的Pod
这里给出了包含一个容器的Pod的配置文件。该容器没有声明CPU请求和CPU限制。
这里给出了包含一个容器的 Pod 的配置文件。该容器没有设定 CPU 请求和 CPU 限制
{{< codenew file="admin/resource/cpu-constraints-pod-4.yaml" >}}
<!--
Create the Pod:
-->
创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-4.yaml --namespace=constraints-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-4.yaml --namespace=constraints-cpu-example
```
<!--
View detailed information about the Pod:
-->
查看 Pod 的详情:
```
@@ -314,8 +290,8 @@ 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?
-->
输出结果显示 Pod 的容器有个800 millicpu的 CPU 请求和800 millicpu的 CPU 限制。容器时怎样得到那些值的呢?
输出结果显示 Pod 的容器有个 800 millicpu 的 CPU 请求和 800 millicpu 的 CPU 限制。
容器是怎样得到那些值的呢?
```yaml
resources:
@@ -330,8 +306,8 @@ Because your Container did not specify its own CPU request and limit, it was giv
[default CPU request and limit](/docs/tasks/administer-cluster/cpu-default-namespace/)
from the LimitRange.
-->
因为你的容器没有声明自己的 CPU 请求和限制,LimitRange 给它指定了[默认的CPU请求和限制](/docs/tasks/administer-cluster/cpu-default-namespace/)
因为你的 Container 没有声明自己的 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
@@ -342,8 +318,10 @@ enough CPU to accommodate the 800 millicpu request.
Delete your Pod:
-->
此时,你的容器可能运行也可能没有运行。回想一下,本任务的先决条件是你的节点要有1 个 CPU。如果你的每个节点仅有1个 CPU,那么可能没有任何一个节点可以满足800 millicpu的 CPU 请求。如果你在用的节点恰好有两个 CPU,那么你才可能有足够的 CPU来满足800 millicpu的请求
此时,你的容器可能运行也可能没有运行。
回想一下,本任务的先决条件是你的节点要有 1 个 CPU。
如果你的每个节点仅有 1 个 CPU,那么可能没有任何一个节点可以满足 800 millicpu 的 CPU 请求。
如果你在用的节点恰好有两个 CPU,那么你才可能有足够的 CPU 来满足 800 millicpu 的请求。
```
kubectl delete pod constraints-cpu-demo-4 --namespace=constraints-cpu-example
@@ -356,21 +334,18 @@ The maximum and minimum CPU constraints imposed on a namespace by a LimitRange a
when a Pod is created or updated. If you change the LimitRange, it does not affect
Pods that were created previously.
-->
## CPU 最小和最大限制的强制执行
只有当Pod创建或者更新时,LimitRange为命名空间规定的CPU最小和最大限制才会被强制执行。如果你对LimitRange进行修改,那不会影响此前创建的Pod。
只有当 Pod 创建或者更新时,LimitRange 为命名空间规定的 CPU 最小和最大限制才会被强制执行。
如果你对 LimitRange 进行修改,那不会影响此前创建的 Pod。
<!--
## Motivation for minimum and maximum CPU constraints
-->
## 最小和最大 CPU 限制范围的动机
<!--
As a cluster administrator, you might want to impose restrictions on the CPU resources that Pods can use.
For example:
-->
## 最小和最大 CPU 限制范围的动机
作为集群管理员,你可能想设定 Pod 可以使用的 CPU 资源限制。例如:
@@ -383,18 +358,17 @@ You want to allow production workloads to consume up to 3 CPU, but you want deve
to 1 CPU. You create separate namespaces for production and development, and you apply CPU constraints to
each namespace.
-->
* 集群中的每个节点有两个 CPU。你不想接受任何请求超过2个 CPU 的 Pod,因为集群中没有节点可以支持这种请求。
* 你的生产和开发部门共享一个集群。你想允许生产工作负载消耗3个 CPU,而开发工作负载的消耗限制为1个 CPU。你为生产和开发创建不同的命名空间,并且为每个命名空间都应用 CPU 限制。
* 集群中的每个节点有两个 CPU。你不想接受任何请求超过 2 个 CPU 的 Pod,因为集群中没有节点可以支持这种请求。
* 你的生产和开发部门共享一个集群。你想允许生产工作负载消耗 3 个 CPU,
而开发部门工作负载的消耗限制为 1 个 CPU。
你可以为生产和开发创建不同的命名空间,并且为每个命名空间都应用 CPU 限制。
<!--
## Clean up
Delete your namespace:
-->
## 环境清理
## 清理
删除你的命名空间:
@@ -402,11 +376,8 @@ Delete your namespace:
kubectl delete namespace constraints-cpu-example
```
## {{% heading "whatsnext" %}}
<!--
### For cluster administrators
@@ -425,34 +396,24 @@ kubectl delete namespace constraints-cpu-example
### 集群管理员参考:
* [为命名空间配置默认内存请求和限制](/docs/tasks/administer-cluster/memory-default-namespace/)
* [为命名空间配置内存限制的最小值和最大值](/docs/tasks/administer-cluster/memory-constraint-namespace/)
* [为命名空间配置 CPU 限制的最小值和最大值](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
* [为命名空间配置 Pod 配额](/docs/tasks/administer-cluster/quota-pod-namespace/)
* [为 API 对象配置配额](/docs/tasks/administer-cluster/quota-api-object/)
* [为命名空间配置默认内存请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)
* [为命名空间配置内存限制的最小值和最大值](/zh/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)
* [为命名空间配置 CPU 限制的最小值和最大值](/zh/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
* [为命名空间配置 Pod 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/)
* [为 API 对象配置配额](/zh/docs/tasks/administer-cluster/quota-api-object/)
<!--
### For app developers
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
-->
### 应用开发者参考:
* [为容器和 Pod 分配内存资源](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [容器和 Pod 分配 CPU 资源](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置 Service 数量](/docs/tasks/configure-pod-container/quality-service-pod/)
* [为容器和 Pod 分配内存资源](/zh/docs/tasks/configure-pod-container/assign-memory-resource/)
* [为容器和 Pod 分配 CPU 资源](/zh/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置 Service 数量](/zh/docs/tasks/configure-pod-container/quality-service-pod/)
@@ -1,15 +1,13 @@
---
title: 为命名空间配置默认的CPU请求和限制
title: 为命名空间配置默认的 CPU 请求和限制
content_type: task
weight: 20
---
<!--
---
title: Configure Default CPU Requests and Limits for a Namespace
content_type: task
weight: 20
---
-->
<!-- overview -->
@@ -20,29 +18,24 @@ that has a default CPU limit, and the Container does not specify its own CPU lim
the Container is assigned the default CPU limit. Kubernetes assigns a default CPU request
under certain conditions that are explained later in this topic.
-->
本章介绍怎样为命名空间配置默认的 CPU 请求和限制。
一个 Kubernetes 集群可被划分为多个命名空间。如果在配置了 CPU 限制的命名空间创建容器,并且该容器没有声明自己的 CPU 限制,那么这个容器会被指定默认的 CPU 限制。Kubernetes 在一些特定情况还会指定 CPU 请求,本文后续章节将会对其进行解释。
一个 Kubernetes 集群可被划分为多个命名空间。如果在配置了 CPU 限制的命名空间创建容器,
并且该容器没有声明自己的 CPU 限制,那么这个容器会被指定默认的 CPU 限制。
Kubernetes 在一些特定情况还会指定 CPU 请求,本文后续章节将会对其进行解释。
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!-- steps -->
<!--
## Create a namespace
-->
## 创建命名空间
<!--
Create a namespace so that the resources you create in this exercise are
isolated from the rest of your cluster.
-->
## 创建命名空间
创建一个命名空间,以便本练习中创建的资源和集群的其余部分相隔离。
@@ -52,14 +45,11 @@ kubectl create namespace default-cpu-example
<!--
## Create a LimitRange and a Pod
-->
创建 LimitRange 和 Pod
<!--
Here's the configuration file for a LimitRange object. The configuration specifies
a default CPU request and a default CPU limit.
-->
## 创建 LimitRange 和 Pod
这里给出了 LimitRange 对象的配置文件。该配置声明了一个默认的 CPU 请求和一个默认的 CPU 限制。
@@ -68,11 +58,10 @@ a default CPU request and a default CPU limit.
<!--
Create the LimitRange in the default-cpu-example namespace:
-->
在命名空间 default-cpu-example 中创建 LimitRange 对象:
```shell
kubectl create -f https://k8s.io/examples/admin/resource/cpu-defaults.yaml --namespace=default-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults.yaml --namespace=default-cpu-example
```
<!--
@@ -84,8 +73,8 @@ CPU limit of 1.
Here's the configuration file for a Pod that has one Container. The Container
does not specify a CPU request and limit.
-->
现在如果在 default-cpu-example 命名空间创建一个容器,该容器没有声明自己的 CPU 请求和限制时,将会给它指定默认的 CPU 请求0.5和默认的 CPU 限制值1.
现在如果在 default-cpu-example 命名空间创建一个容器,该容器没有声明自己的 CPU 请求和限制时,
将会给它指定默认的 CPU 请求0.5和默认的 CPU 限制值1.
这里给出了包含一个容器的 Pod 的配置文件。该容器没有声明 CPU 请求和限制。
@@ -94,17 +83,15 @@ does not specify a CPU request and limit.
<!--
Create the Pod.
-->
创建 Pod。
```shell
kubectl create -f https://k8s.io/examples/admin/resource/cpu-defaults-pod.yaml --namespace=default-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod.yaml --namespace=default-cpu-example
```
<!--
View the Pod's specification:
-->
查看该 Pod 的声明:
```shell
@@ -115,7 +102,6 @@ kubectl get pod default-cpu-demo --output=yaml --namespace=default-cpu-example
The output shows that the Pod's Container has a CPU request of 500 millicpus and
a CPU limit of 1 cpu. These are the default values specified by the LimitRange.
-->
输出显示该 Pod 的容器有一个500 millicpus的 CPU 请求和一个1 cpu的 CPU 限制。这些是 LimitRange 声明的默认值。
```shell
@@ -132,14 +118,11 @@ containers:
<!--
## What if you specify a Container's limit, but not its request?
-->
## 你只声明容器的限制,而不声明请求会怎么样?
<!--
Here's the configuration file for a Pod that has one Container. The Container
specifies a CPU limit, but not a request:
-->
## 你只声明容器的限制,而不声明请求会怎么样?
这是包含一个容器的 Pod 的配置文件。该容器声明了 CPU 限制,而没有声明 CPU 请求。
@@ -148,17 +131,15 @@ specifies a CPU limit, but not a request:
<!--
Create the Pod:
-->
创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-2.yaml --namespace=default-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-2.yaml --namespace=default-cpu-example
```
<!--
View the Pod specification:
-->
查看 Pod 的声明:
```
@@ -169,7 +150,6 @@ kubectl get pod default-cpu-demo-2 --output=yaml --namespace=default-cpu-example
The output shows that the Container's CPU request is set to match its CPU limit.
Notice that the Container was not assigned the default CPU request value of 0.5 cpu.
-->
输出显示该容器的 CPU 请求和 CPU 限制设置相同。注意该容器没有被指定默认的 CPU 请求值0.5 cpu。
```
@@ -182,14 +162,11 @@ resources:
<!--
## What if you specify a Container's request, but not its limit?
-->
## 你只声明容器的请求,而不声明它的限制会怎么样?
<!--
Here's the configuration file for a Pod that has one Container. The Container
specifies a CPU request, but not a limit:
-->
## 你只声明容器的请求,而不声明它的限制会怎么样?
这里给出了包含一个容器的 Pod 的配置文件。该容器声明了 CPU 请求,而没有声明 CPU 限制。
@@ -198,18 +175,16 @@ specifies a CPU request, but not a limit:
<!--
Create the Pod:
-->
创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-3.yaml --namespace=default-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-3.yaml --namespace=default-cpu-example
```
<!--
View the Pod specification:
-->
查看 Pod 的声明:
查看 Pod 的规约:
```
kubectl get pod default-cpu-demo-3 --output=yaml --namespace=default-cpu-example
@@ -220,8 +195,8 @@ The output shows that the Container's CPU request is set to the value specified
Container's configuration file. The Container's CPU limit is set to 1 cpu, which is the
default CPU limit for the namespace.
-->
结果显示该容器的 CPU 请求被设置为容器配置文件中声明的数值。容器的CPU限制被设置为1 cpu,即该命名空间的默认 CPU 限制值。
结果显示该容器的 CPU 请求被设置为容器配置文件中声明的数值。
容器的CPU限制被设置为 1 CPU,即该命名空间的默认 CPU 限制值。
```
resources:
@@ -233,11 +208,7 @@ resources:
<!--
## Motivation for default CPU limits and requests
-->
## 默认 CPU 限制和请求的动机
<!--
If your namespace has a
[resource quota](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/),
it is helpful to have a default value in place for CPU limit.
@@ -249,69 +220,49 @@ Here are two of the restrictions that a resource quota imposes on a namespace:
If a Container does not specify its own CPU limit, it is given the default limit, and then
it can be allowed to run in a namespace that is restricted by a quota.
-->
## 默认 CPU 限制和请求的动机
如果你的命名空间有一个[资源配额](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/),那么有一个默认的 CPU 限制是有帮助的。这里有两条资源配额强加给命名空间的限制:
如果你的命名空间有一个
[资源配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
那么有一个默认的 CPU 限制是有帮助的。这里有资源配额强加给命名空间的两条限制:
* 命名空间中运行的每个容器必须有自己的 CPU 限制。
* 命名空间中所有容器使用的 CPU 总和不能超过一个声明值。
如果容器没有声明自己的 CPU 限制,将会给它一个默认限制,这样它就能被允许运行在一个有配额限制的命名空间中。
## {{% heading "whatsnext" %}}
<!--
### For cluster administrators
-->
### 集群管理员参考
<!--
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
-->
### 集群管理员参考
* [为命名空间配置默认内存请求和限制](/docs/tasks/administer-cluster/memory-default-namespace/)
* [为命名空间配置内存限制的最小值和最大值](/docs/tasks/administer-cluster/memory-constraint-namespace/)
* [为命名空间配置 CPU 限制的最小值和最大值](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
* [为命名空间配置 Pod 配额](/docs/tasks/administer-cluster/quota-pod-namespace/)
* [为 API 对象配置配额](/docs/tasks/administer-cluster/quota-api-object/)
* [为命名空间配置默认内存请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)
* [为命名空间配置内存限制的最小值和最大值](/zh/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)
* [为命名空间配置 CPU 限制的最小值和最大值](/zh/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
* [为命名空间配置 Pod 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/)
* [为 API 对象配置配额](/zh/docs/tasks/administer-cluster/quota-api-object/)
<!--
### For app developers
-->
### 应用开发者参考
<!--
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
-->
### 应用开发者参考
* [为容器和 Pod 分配内存资源](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [容器和 Pod 分配 CPU 资源](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置 Service 数量](/docs/tasks/configure-pod-container/quality-service-pod/)
* [为容器和 Pod 分配内存资源](/zh/docs/tasks/configure-pod-container/assign-memory-resource/)
* [为容器和 Pod 分配 CPU 资源](/zh/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置 Service 数量](/zh/docs/tasks/configure-pod-container/quality-service-pod/)
@@ -5,11 +5,9 @@ weight: 30
---
<!--
---
title: Configure Minimum and Maximum Memory Constraints for a Namespace
content_type: task
weight: 30
---
-->
<!-- overview -->
@@ -21,25 +19,18 @@ running in a namespace. You specify minimum and maximum memory values in a
object. If a Pod does not meet the constraints imposed by the LimitRange,
it cannot be created in the namespace.
-->
此页面介绍如何设置在命名空间中运行的容器使用的内存的最小值和最大值。 您可以在 [LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)对象中指定最小和最大内存值。 如果 Pod 不满足 LimitRange 施加的约束,则无法在命名空间中创建它。
本页介绍如何设置在命名空间中运行的容器使用的内存的最小值和最大值。 你可以在
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
对象中指定最小和最大内存值。如果 Pod 不满足 LimitRange 施加的约束,则无法在命名空间中创建它。
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!--
Each node in your cluster must have at least 1 GiB of memory.
-->
集群中每个节点必须至少要有1 GiB 的内存。
集群中每个节点必须至少要有 1 GiB 的内存。
<!-- steps -->
@@ -49,7 +40,6 @@ Each node in your cluster must have at least 1 GiB of memory.
Create a namespace so that the resources you create in this exercise are
isolated from the rest of your cluster.
-->
## 创建命名空间
创建一个命名空间,以便在此练习中创建的资源与群集的其余资源隔离。
@@ -63,28 +53,24 @@ kubectl create namespace constraints-mem-example
Here's the configuration file for a LimitRange:
-->
## 创建 LimitRange 和 Pod
下面是 LimitRange 的配置文件:
{{< codenew file="admin/resource/memory-constraints.yaml" >}}
<!--
Create the LimitRange:
-->
创建 LimitRange:
```shell
kubectl create -f https://k8s.io/examples/admin/resource/memory-constraints.yaml --namespace=constraints-mem-example
kubectl apply -f https://k8s.io/examples/admin/resource/memory-constraints.yaml --namespace=constraints-mem-example
```
<!--
View detailed information about the LimitRange:
-->
查看 LimitRange 的详情:
```shell
@@ -96,8 +82,7 @@ The output shows the minimum and maximum memory constraints as expected. But
notice that even though you didn't specify default values in the configuration
file for the LimitRange, they were created automatically.
-->
输出显示预期的最小和最大内存约束。 但请注意,即使您没有在 LimitRange 的配置文件中指定默认值,也会自动创建它们。
输出显示预期的最小和最大内存约束。 但请注意,即使你没有在 LimitRange 的配置文件中指定默认值,也会自动创建它们。
```
limits:
@@ -127,7 +112,6 @@ Here's the configuration file for a Pod that has one Container. The Container ma
specifies a memory request of 600 MiB and a memory limit of 800 MiB. These satisfy the
minimum and maximum memory constraints imposed by the LimitRange.
-->
现在,只要在 constraints-mem-example 命名空间中创建容器,Kubernetes 就会执行下面的步骤:
* 如果 Container 未指定自己的内存请求和限制,将为它指定默认的内存请求和限制。
@@ -136,24 +120,23 @@ minimum and maximum memory constraints imposed by the LimitRange.
* 验证 Container 的内存限制是否小于或等于1 GiB。
这里给出了包含一个 Container 的 Pod 配置文件。Container 声明了600 MiB 的内存请求和800 MiB 的内存限制, 这些满足了 LimitRange 施加的最小和最大内存约束。
这里给出了包含一个 Container 的 Pod 配置文件。Container 声明了 600 MiB 的内存请求和
800 MiB 的内存限制, 这些满足了 LimitRange 施加的最小和最大内存约束。
{{< codenew file="admin/resource/memory-constraints-pod.yaml" >}}
<!--
Create the Pod:
-->
创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/memory-constraints-pod.yaml --namespace=constraints-mem-example
kubectl apply -f https://k8s.io/examples/admin/resource/memory-constraints-pod.yaml --namespace=constraints-mem-example
```
<!--
Verify that the Pod's Container is running:
-->
确认下 Pod 中的容器在运行:
```shell
@@ -163,7 +146,6 @@ kubectl get pod constraints-mem-demo --namespace=constraints-mem-example
<!--
View detailed information about the Pod:
-->
查看 Pod 详情:
```shell
@@ -174,7 +156,6 @@ kubectl get pod constraints-mem-demo --output=yaml --namespace=constraints-mem-e
The output shows that the Container has a memory request of 600 MiB and a memory limit
of 800 MiB. These satisfy the constraints imposed by the LimitRange.
-->
输出结果显示容器的内存请求为600 MiB,内存限制为800 MiB。这些满足了 LimitRange 设定的限制范围。
```yaml
@@ -188,7 +169,6 @@ resources:
<!--
Delete your Pod:
-->
删除你创建的 Pod
```shell
@@ -201,7 +181,6 @@ kubectl delete pod constraints-mem-demo --namespace=constraints-mem-example
Here's the configuration file for a Pod that has one Container. The Container specifies a
memory request of 800 MiB and a memory limit of 1.5 GiB.
-->
## 尝试创建一个超过最大内存限制的 Pod
这里给出了包含一个容器的 Pod 的配置文件。容器声明了800 MiB 的内存请求和1.5 GiB 的内存限制。
@@ -211,18 +190,16 @@ memory request of 800 MiB and a memory limit of 1.5 GiB.
<!--
Attempt to create the Pod:
-->
尝试创建 Pod:
```shell
kubectl create -f https://k8s.io/examples/admin/resource/memory-constraints-pod-2.yaml --namespace=constraints-mem-example
kubectl apply -f https://k8s.io/examples/admin/resource/memory-constraints-pod-2.yaml --namespace=constraints-mem-example
```
<!--
The output shows that the Pod does not get created, because the Container specifies a memory limit that is
too large:
-->
输出结果显示 Pod 没有创建成功,因为容器声明的内存限制太大了:
```
@@ -236,7 +213,6 @@ pods "constraints-mem-demo-2" is forbidden: maximum memory usage per Container i
Here's the configuration file for a Pod that has one Container. The Container specifies a
memory request of 100 MiB and a memory limit of 800 MiB.
-->
## 尝试创建一个不满足最小内存请求的 Pod
这里给出了包含一个容器的 Pod 的配置文件。容器声明了100 MiB 的内存请求和800 MiB 的内存限制。
@@ -246,18 +222,16 @@ memory request of 100 MiB and a memory limit of 800 MiB.
<!--
Attempt to create the Pod:
-->
尝试创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/memory-constraints-pod-3.yaml --namespace=constraints-mem-example
kubectl apply -f https://k8s.io/examples/admin/resource/memory-constraints-pod-3.yaml --namespace=constraints-mem-example
```
<!--
The output shows that the Pod does not get created, because the Container specifies a memory
request that is too small:
-->
输出结果显示 Pod 没有创建成功,因为容器声明的内存请求太小了:
```
@@ -271,7 +245,6 @@ pods "constraints-mem-demo-3" is forbidden: minimum memory usage per Container i
Here's the configuration file for a Pod that has one Container. The Container does not
specify a memory request, and it does not specify a memory limit.
-->
## 创建一个没有声明内存请求和限制的 Pod
这里给出了包含一个容器的 Pod 的配置文件。容器没有声明内存请求,也没有声明内存限制。
@@ -281,17 +254,15 @@ specify a memory request, and it does not specify a memory limit.
<!--
Create the Pod:
-->
创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/memory-constraints-pod-4.yaml --namespace=constraints-mem-example
kubectl apply -f https://k8s.io/examples/admin/resource/memory-constraints-pod-4.yaml --namespace=constraints-mem-example
```
<!--
View detailed information about the Pod:
-->
查看 Pod 详情:
```
@@ -302,7 +273,6 @@ kubectl get pod constraints-mem-demo-4 --namespace=constraints-mem-example --out
The output shows that the Pod's Container has a memory request of 1 GiB and a memory limit of 1 GiB.
How did the Container get those values?
-->
输出结果显示 Pod 的内存请求为1 GiB,内存限制为1 GiB。容器怎样获得哪些数值呢?
```
@@ -318,8 +288,8 @@ Because your Container did not specify its own memory request and limit, it was
[default memory request and limit](/docs/tasks/administer-cluster/memory-default-namespace/)
from the LimitRange.
-->
因为你的容器没有声明自己的内存请求和限制,它从 LimitRange 那里获得了[默认的内存请求和限制](/docs/tasks/administer-cluster/memory-default-namespace/)。
因为你的容器没有声明自己的内存请求和限制,它从 LimitRange 那里获得了
[默认的内存请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)。
<!--
At this point, your Container might be running or it might not be running. Recall that a prerequisite
@@ -330,8 +300,9 @@ enough space to accommodate the 1 GiB request.
Delete your Pod:
-->
此时,你的容器可能运行起来也可能没有运行起来。回想一下我们本次任务的先决条件是你的每个节点都至少有1 GiB 的内存。如果你的每个节点都只有1 GiB 的内存,那将没有一个节点拥有足够的可分配内存来满足1 GiB 的内存请求。
此时,你的容器可能运行起来也可能没有运行起来。
回想一下我们本次任务的先决条件是你的每个节点都至少有1 GiB 的内存。
如果你的每个节点都只有1 GiB 的内存,那将没有一个节点拥有足够的可分配内存来满足1 GiB 的内存请求。
删除你的 Pod
@@ -346,15 +317,14 @@ The maximum and minimum memory constraints imposed on a namespace by a LimitRang
when a Pod is created or updated. If you change the LimitRange, it does not affect
Pods that were created previously.
-->
## 强制执行内存最小和最大限制
LimitRange 为命名空间设定的最小和最大内存限制只有在 Pod 创建和更新时才会强制执行。如果你更新 LimitRange,它不会影响此前创建的 Pod。
LimitRange 为命名空间设定的最小和最大内存限制只有在 Pod 创建和更新时才会强制执行。
如果你更新 LimitRange,它不会影响此前创建的 Pod。
<!--
## Motivation for minimum and maximum memory constraints
-->
## 设置内存最小和最大限制的动因
<!--
@@ -362,25 +332,26 @@ As a cluster administrator, you might want to impose restrictions on the amount
For example:
* Each Node in a cluster has 2 GB of memory. You do not want to accept any Pod that requests
more than 2 GB of memory, because no Node in the cluster can support the request.
more than 2 GB of memory, because no Node in the cluster can support the request.
* A cluster is shared by your production and development departments.
You want to allow production workloads to consume up to 8 GB of memory, but
you want development workloads to be limited to 512 MB. You create separate namespaces
for production and development, and you apply memory constraints to each namespace.
You want to allow production workloads to consume up to 8 GB of memory, but
you want development workloads to be limited to 512 MB. You create separate namespaces
for production and development, and you apply memory constraints to each namespace.
-->
做为集群管理员,你可能想规定 Pod 可以使用的内存总量限制。例如:
* 集群的每个节点有2 GB 内存。你不想接受任何请求超过2 GB 的 Pod,因为集群中没有节点可以满足。
* 集群的每个节点有 2 GB 内存。你不想接受任何请求超过 2 GB 的 Pod,因为集群中没有节点可以满足。
* 集群由生产部门和开发部门共享。你希望允许产品部门的负载最多耗用 8 GB 内存,
但是开发部门的负载最多可使用 512 MiB。
这时,你可以为产品部门和开发部门分别创建名字空间,并为各个名字空间设置内存约束。
<!--
## Clean up
Delete your namespace:
-->
## 数据清理
## 清理
删除你的命名空间:
@@ -388,57 +359,39 @@ Delete your namespace:
kubectl delete namespace constraints-mem-example
```
## {{% heading "whatsnext" %}}
<!--
### For cluster administrators
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
-->
### 集群管理员参考
* [为命名空间配置默认内存请求和限制](/docs/tasks/administer-cluster/memory-default-namespace/)
* [为命名空间配置内存限制的最小值和最大值](/docs/tasks/administer-cluster/memory-constraint-namespace/)
* [为命名空间配置 CPU 限制的最小值和最大值](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
* [为命名空间配置 Pod 配额](/docs/tasks/administer-cluster/quota-pod-namespace/)
* [为 API 对象配置配额](/docs/tasks/administer-cluster/quota-api-object/)
* [为命名空间配置默认内存请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)
* [为命名空间配置内存限制的最小值和最大值](/zh/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)
* [为命名空间配置 CPU 限制的最小值和最大值](/zh/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
* [为命名空间配置 Pod 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/)
* [为 API 对象配置配额](/zh/docs/tasks/administer-cluster/quota-api-object/)
<!--
### For app developers
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
-->
### 应用开发者参考
* [为容器和 Pod 分配内存资源](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [容器和 Pod 分配 CPU 资源](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置 Service 数量](/docs/tasks/configure-pod-container/quality-service-pod/)
* [为容器和 Pod 分配内存资源](/zh/docs/tasks/configure-pod-container/assign-memory-resource/)
* [为容器和 Pod 分配 CPU 资源](/zh/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置 Service 数量](/zh/docs/tasks/configure-pod-container/quality-service-pod/)
@@ -5,11 +5,9 @@ weight: 10
---
<!--
---
title: Configure Default Memory Requests and Limits for a Namespace
content_type: task
weight: 10
---
-->
<!-- overview -->
@@ -21,35 +19,29 @@ does not specify its own memory limit, then the Container is assigned the defaul
Kubernetes assigns a default memory request under certain conditions that are explained later in this topic.
-->
本文介绍怎样给命名空间配置默认的内存请求和限制。如果在一个有默认内存限制的命名空间创建容器,该容器没有声明自己的内存限制时,将会被指定默认内存限制。Kubernetes 还为某些情况指定了默认的内存请求,本章后面会进行介绍。
本文介绍怎样给命名空间配置默认的内存请求和限制。
如果在一个有默认内存限制的命名空间创建容器,该容器没有声明自己的内存限制时,
将会被指定默认内存限制。
Kubernetes 还为某些情况指定了默认的内存请求,本章后面会进行介绍。
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!--
Each node in your cluster must have at least 2 GiB of memory.
-->
你的集群中的每个节点必须至少有2 GiB的内存。
你的集群中的每个节点必须至少有 2 GiB 的内存。
<!-- steps -->
<!--
## Create a namespace
-->
## 创建命名空间
<!--
Create a namespace so that the resources you create in this exercise are
isolated from the rest of your cluster.
-->
## 创建命名空间
创建一个命名空间,以便本练习中所建的资源与集群的其余资源相隔离。
@@ -59,14 +51,11 @@ kubectl create namespace default-mem-example
<!--
## Create a LimitRange and a Pod
-->
## 创建 LimitRange 和 Pod
<!--
Here's the configuration file for a LimitRange object. The configuration specifies
a default memory request and a default memory limit.
-->
## 创建 LimitRange 和 Pod
这里给出了一个限制范围对象的配置文件。该配置声明了一个默认的内存请求和一个默认的内存限制。
@@ -75,11 +64,10 @@ a default memory request and a default memory limit.
<!--
Create the LimitRange in the default-mem-example namespace:
-->
在 default-mem-example 命名空间创建限制范围:
```shell
kubectl create -f https://k8s.io/examples/admin/resource/memory-defaults.yaml --namespace=default-mem-example
kubectl apply -f https://k8s.io/examples/admin/resource/memory-defaults.yaml --namespace=default-mem-example
```
<!--
@@ -91,25 +79,23 @@ memory limit of 512 MiB.
Here's the configuration file for a Pod that has one Container. The Container
does not specify a memory request and limit.
-->
现在,如果在 default-mem-example 命名空间创建容器,并且该容器没有声明自己的内存请求和限制值,它将被指定一个默认的内存请求256 MiB和一个默认的内存限制512 Mib
现在,如果在 default-mem-example 命名空间创建容器,并且该容器没有声明自己的内存请求和限制值,
它将被指定默认的内存请求 256 MiB 和默认的内存限制 512 MiB
{{< codenew file="admin/resource/memory-defaults-pod.yaml" >}}
<!--
Create the Pod.
-->
创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/memory-defaults-pod.yaml --namespace=default-mem-example
kubectl apply -f https://k8s.io/examples/admin/resource/memory-defaults-pod.yaml --namespace=default-mem-example
```
<!--
View detailed information about the Pod:
-->
查看 Pod 的详情:
```shell
@@ -120,8 +106,8 @@ kubectl get pod default-mem-demo --output=yaml --namespace=default-mem-example
The output shows that the Pod's Container has a memory request of 256 MiB and
a memory limit of 512 MiB. These are the default values specified by the LimitRange.
-->
输出内容显示该Pod的容器有一个256 MiB的内存请求和一个512 MiB的内存限制。这些都是限制范围声明的默认值。
输出内容显示该 Pod 的容器有 256 MiB 的内存请求和 512 MiB 的内存限制。
这些都是 LimitRange 设置的默认值。
```shell
containers:
@@ -138,7 +124,6 @@ containers:
<!--
Delete your Pod:
-->
删除你的 Pod
```shell
@@ -147,14 +132,11 @@ kubectl delete pod default-mem-demo --namespace=default-mem-example
<!--
## What if you specify a Container's limit, but not its request?
-->
## 声明容器的限制而不声明它的请求会怎么样?
<!--
Here's the configuration file for a Pod that has one Container. The Container
specifies a memory limit, but not a request:
-->
## 声明容器的限制而不声明它的请求会怎么样?
这里给出了包含一个容器的 Pod 的配置文件。该容器声明了内存限制,而没有声明内存请求:
@@ -163,17 +145,15 @@ specifies a memory limit, but not a request:
<!--
Create the Pod:
-->
创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/memory-defaults-pod-2.yaml --namespace=default-mem-example
kubectl apply -f https://k8s.io/examples/admin/resource/memory-defaults-pod-2.yaml --namespace=default-mem-example
```
<!--
View detailed information about the Pod:
-->
查看 Pod 的详情:
```shell
@@ -184,8 +164,7 @@ kubectl get pod default-mem-demo-2 --output=yaml --namespace=default-mem-example
The output shows that the Container's memory request is set to match its memory limit.
Notice that the Container was not assigned the default memory request value of 256Mi.
-->
输出结果显示容器的内存请求被设置为它的内存限制相同的值。注意该容器没有被指定默认的内存请求值256Mi。
输出结果显示容器的内存请求被设置为它的内存限制相同的值。注意该容器没有被指定默认的内存请求值 256MiB。
```
resources:
@@ -198,14 +177,12 @@ resources:
<!--
## What if you specify a Container's request, but not its limit?
-->
## 声明容器的内存请求而不声明内存限制会怎么样?
<!--
Here's the configuration file for a Pod that has one Container. The Container
specifies a memory request, but not a limit:
-->
这里给出了一个包含一个容器的 Pod 的配置文件。该容器声明了内存请求,但没有内存限制:
{{< codenew file="admin/resource/memory-defaults-pod-3.yaml" >}}
@@ -213,17 +190,15 @@ specifies a memory request, but not a limit:
<!--
Create the Pod:
-->
创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/memory-defaults-pod-3.yaml --namespace=default-mem-example
kubectl apply -f https://k8s.io/examples/admin/resource/memory-defaults-pod-3.yaml --namespace=default-mem-example
```
<!--
View the Pod's specification:
-->
查看 Pod 声明:
```shell
@@ -235,8 +210,8 @@ The output shows that the Container's memory request is set to the value specifi
Container's configuration file. The Container's memory limit is set to 512Mi, which is the
default memory limit for the namespace.
-->
输出结果显示该容器的内存请求被设置为了容器配置文件中声明的数值。容器的内存限制被设置为512Mi,即命名空间的默认内存限制。
输出结果显示该容器的内存请求被设置为了容器配置文件中声明的数值。
容器的内存限制被设置为 512MiB,即命名空间的默认内存限制。
```
resources:
@@ -248,23 +223,20 @@ resources:
<!--
## Motivation for default memory limits and requests
-->
## 设置默认内存限制和请求的动机
<!--
If your namespace has a resource quota,
it is helpful to have a default value in place for memory limit.
Here are two of the restrictions that a resource quota imposes on a namespace:
-->
## 设置默认内存限制和请求的动机
如果你的命名空间有资源配额,那么默认内存限制是很有帮助的。下面是一个例子,通过资源配额为命名空间设置两项约束:
如果你的命名空间有资源配额,那么默认内存限制是很有帮助的。
下面是一个例子,通过资源配额为命名空间设置两项约束:
<!--
* Every Container that runs in the namespace must have its own memory limit.
* The total amount of memory used by all Containers in the namespace must not exceed a specified limit.
-->
* 运行在命名空间中的每个容器必须有自己的内存限制。
* 命名空间中所有容器的内存使用量之和不能超过声明的限制值。
@@ -272,21 +244,13 @@ Here are two of the restrictions that a resource quota imposes on a namespace:
If a Container does not specify its own memory limit, it is given the default limit, and then
it can be allowed to run in a namespace that is restricted by a quota.
-->
如果一个容器没有声明自己的内存限制,会被指定默认限制,然后它才会被允许在限定了配额的命名空间中运行。
## {{% heading "whatsnext" %}}
<!--
### For cluster administrators
-->
### 集群管理员参考
<!--
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
@@ -299,37 +263,27 @@ it can be allowed to run in a namespace that is restricted by a quota.
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
-->
### 集群管理员参考
* [为命名空间配置默认的 CPU 请求和限制](/docs/tasks/administer-cluster/cpu-default-namespace/)
* [为命名空间配置最小和最大内存限制](/docs/tasks/administer-cluster/memory-constraint-namespace/)
* [为命名空间配置最小和最大 CPU 限制](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
* [为命名空间配置 Pod 配额](/docs/tasks/administer-cluster/quota-pod-namespace/)
* [为 API 对象配置配额](/docs/tasks/administer-cluster/quota-api-object/)
* [为命名空间配置默认的 CPU 请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
* [为命名空间配置最小和最大内存限制](/zh/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)
* [为命名空间配置最小和最大 CPU 限制](/zh/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
* [为命名空间配置 Pod 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/)
* [为 API 对象配置配额](/zh/docs/tasks/administer-cluster/quota-api-object/)
<!--
### For app developers
-->
### 应用开发者参考
<!--
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
-->
### 应用开发者参考
* [为容器和 Pod 分配内存资源](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [容器和 Pod 分配 CPU 资源](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置服务数量](/docs/tasks/configure-pod-container/quality-service-pod/)
* [为容器和 Pod 分配内存资源](/zh/docs/tasks/configure-pod-container/assign-memory-resource/)
* [为容器和 Pod 分配 CPU 资源](/zh/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置服务数量](/zh/docs/tasks/configure-pod-container/quality-service-pod/)
@@ -5,11 +5,9 @@ weight: 50
---
<!--
---
title: Configure Memory and CPU Quotas for a Namespace
content_type: task
weight: 50
---
-->
<!-- overview -->
@@ -20,27 +18,18 @@ 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)
object.
-->
本文介绍怎样为命名空间设置容器可用的内存和 CPU 总量。你可以通过 [ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
本文介绍怎样为命名空间设置容器可用的内存和 CPU 总量。你可以通过
[ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
对象设置配额.
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!--
Each node in your cluster must have at least 1 GiB of memory.
-->
集群中每个节点至少有1 GiB的内存。
集群中每个节点至少有 1 GiB 的内存。
<!-- steps -->
@@ -64,7 +53,6 @@ kubectl create namespace quota-mem-cpu-example
Here is the configuration file for a ResourceQuota object:
-->
## 创建 ResourceQuota
这里给出一个 ResourceQuota 对象的配置文件:
@@ -74,17 +62,15 @@ Here is the configuration file for a ResourceQuota object:
<!--
Create the ResourceQuota:
-->
创建 ResourceQuota
```shell
kubectl create -f https://k8s.io/examples/admin/resource/quota-mem-cpu.yaml --namespace=quota-mem-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/quota-mem-cpu.yaml --namespace=quota-mem-cpu-example
```
<!--
View detailed information about the ResourceQuota:
-->
查看 ResourceQuota 详情:
```shell
@@ -100,7 +86,6 @@ The ResourceQuota places these requirements on the quota-mem-cpu-example namespa
* The CPU request total for all Containers must not exceed 1 cpu.
* The CPU limit total for all Containers must not exceed 2 cpu.
-->
ResourceQuota 在 quota-mem-cpu-example 命名空间中设置了如下要求:
* 每个容器必须有内存请求和限制,以及 CPU 请求和限制。
@@ -114,28 +99,24 @@ ResourceQuota 在 quota-mem-cpu-example 命名空间中设置了如下要求:
Here is the configuration file for a Pod:
-->
## 创建 Pod
这里给出 Pod 的配置文件:
{{< codenew file="admin/resource/quota-mem-cpu-pod.yaml" >}}
<!--
Create the Pod:
-->
创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/quota-mem-cpu-pod.yaml --namespace=quota-mem-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/quota-mem-cpu-pod.yaml --namespace=quota-mem-cpu-example
```
<!--
Verify that the Pod's Container is running:
-->
检查下 Pod 中的容器在运行:
```
@@ -145,7 +126,6 @@ kubectl get pod quota-mem-cpu-demo --namespace=quota-mem-cpu-example
<!--
Once again, view detailed information about the ResourceQuota:
-->
再查看 ResourceQuota 的详情:
```
@@ -157,7 +137,6 @@ The output shows the quota along with how much of the quota has been used.
You can see that the memory and CPU requests and limits for your Pod do not
exceed the quota.
-->
输出结果显示了配额以及有多少配额已经被使用。你可以看到 Pod 的内存和 CPU 请求值及限制值没有超过配额。
```
@@ -179,7 +158,6 @@ status:
Here is the configuration file for a second Pod:
-->
## 尝试创建第二个 Pod
这里给出了第二个 Pod 的配置文件:
@@ -194,19 +172,20 @@ request exceeds the memory request quota. 600 MiB + 700 MiB > 1 GiB.
Attempt to create the Pod:
-->
配置文件中,你可以看到 Pod 的内存请求为700 MiB。请注意新的内存请求与已经使用的内存请求只和超过了内存请求的配额。600 MiB + 700 MiB > 1 GiB。
配置文件中,你可以看到 Pod 的内存请求为 700 MiB。
请注意新的内存请求与已经使用的内存请求只和超过了内存请求的配额。
600 MiB + 700 MiB > 1 GiB。
尝试创建 Pod
```shell
kubectl create -f https://k8s.io/examples/admin/resource/quota-mem-cpu-pod-2.yaml --namespace=quota-mem-cpu-example
kubectl apply -f https://k8s.io/examples/admin/resource/quota-mem-cpu-pod-2.yaml --namespace=quota-mem-cpu-example
```
<!--
The second Pod does not get created. The output shows that creating the second Pod
would cause the memory request total to exceed the memory request quota.
-->
第二个 Pod 不能被创建成功。输出结果显示创建第二个 Pod 会导致内存请求总量超过内存请求配额。
```
@@ -225,20 +204,20 @@ 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/).
-->
## 讨论
如你在本练习中所见,你可以用 ResourceQuota 限制命名空间中所有容器的内存请求总量。同样你也可以限制内存限制总量、CPU 请求总量、CPU 限制总量。
如你在本练习中所见,你可以用 ResourceQuota 限制命名空间中所有容器的内存请求总量。
同样你也可以限制内存限制总量、CPU 请求总量、CPU 限制总量。
如果你想对单个容器而不是所有容器进行限制,就请使用 [LimitRange](/docs/tasks/administer-cluster/memory-constraint-namespace/)。
如果你想对单个容器而不是所有容器进行限制,就请使用
[LimitRange](/zh/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)。
<!--
## Clean up
Delete your namespace:
-->
## 数据清理
## 清理
删除你的命名空间:
@@ -246,57 +225,38 @@ Delete your namespace:
kubectl delete namespace quota-mem-cpu-example
```
## {{% heading "whatsnext" %}}
<!--
### For cluster administrators
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
-->
### 集群管理员参考
* [为命名空间配置默认内存请求和限制](/docs/tasks/administer-cluster/memory-default-namespace/)
* [为命名空间配置内存限制的最小值和最大值](/docs/tasks/administer-cluster/memory-constraint-namespace/)
* [为命名空间配置 CPU 限制的最小值和最大值](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
* [为命名空间配置 Pod 配额](/docs/tasks/administer-cluster/quota-pod-namespace/)
* [为 API 对象配置配额](/docs/tasks/administer-cluster/quota-api-object/)
* [为命名空间配置默认内存请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)
* [为命名空间配置内存限制的最小值和最大值](/zh/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)
* [为命名空间配置 CPU 限制的最小值和最大值](/zh/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
* [为命名空间配置 Pod 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/)
* [为 API 对象配置配额](/zh/docs/tasks/administer-cluster/quota-api-object/)
<!--
### For app developers
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
-->
### 应用开发者参考
* [为容器和 Pod 分配内存资源](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [容器和 Pod 分配CPU资源](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置 Service 数量](/docs/tasks/configure-pod-container/quality-service-pod/)
* [为容器和 Pod 分配内存资源](/zh/docs/tasks/configure-pod-container/assign-memory-resource/)
* [为容器和 Pod 分配CPU资源](/zh/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [为 Pod 配置 Service 数量](/zh/docs/tasks/configure-pod-container/quality-service-pod/)
@@ -1,28 +1,34 @@
---
title: 配置命名空间下pod总数
title: 配置命名空间下 Pod 配额
content_type: task
weight: 60
---
<!-- overview -->
本文主要描述如何配置一个命名空间下可运行的pod总数。资源配额详细信息可查看:[资源配额](/docs/api-reference/v1.7/#resourcequota-v1-core)
<!--
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)
object.
-->
本文主要描述如何配置一个命名空间下可运行的 Pod 个数配额。
你可以使用
[ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
对象来配置配额。
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!-- steps -->
<!--
## Create a namespace
Create a namespace so that the resources you create in this exercise are
isolated from the rest of your cluster.
-->
## 创建一个命名空间
首先创建一个命名空间,这样可以将本次操作中创建的资源与集群其他资源隔离开来。
@@ -31,25 +37,39 @@ weight: 60
kubectl create namespace quota-pod-example
```
## 创建资源配额
<!--
## Create a ResourceQuota
下面是一个资源配额的配置文件:
Here is the configuration file for a ResourceQuota object:
-->
## 创建 ResourceQuota
下面是一个 ResourceQuota 的配置文件:
{{< codenew file="admin/resource/quota-pod.yaml" >}}
创建这个资源配额:
<!-- 创建 ResourceQuota: -->
创建这个 ResourceQuota
```shell
kubectl apply -f https://k8s.io/examples/admin/resource/quota-pod.yaml --namespace=quota-pod-example
```
<!--
View detailed information about the ResourceQuota:
-->
查看资源配额的详细信息:
```shell
kubectl get resourcequota pod-demo --namespace=quota-pod-example --output=yaml
```
从输出的信息我们可以看到,该命名空间下pod的配额是2个,目前创建的pods数为0,配额使用率为0。
<!--
The output shows that the namespace has a quota of two Pods, and that currently there are
no Pods; that is, none of the quota is used.
-->
从输出的信息我们可以看到,该命名空间下 Pod 的配额是 2 个,目前创建的 Pod 数为 0,
配额使用率为 0。
```yaml
spec:
@@ -62,25 +82,40 @@ status:
pods: "0"
```
下面是一个Deployment的配置文件:
<!--
Here is the configuration file for a Deployment:
-->
下面是一个 Deployment 的配置文件:
{{< codenew file="admin/resource/quota-pod-deployment.yaml" >}}
在配置文件中, `replicas: 3` 告诉kubernetes尝试创建三个pods,且运行相同的应用。
<!--
In the configuration file, `replicas: 3` tells Kubernetes to attempt to create three Pods, all running the same application.
创建这个Deployment
Create the Deployment:
-->
在配置文件中,`replicas: 3` 告诉 Kubernetes 尝试创建三个 Pods,且运行相同的应用。
创建这个 Deployment
```shell
kubectl apply -f https://k8s.io/examples/admin/resource/quota-pod-deployment.yaml --namespace=quota-pod-example
```
查看Deployment的详细信息:
<!--
View detailed information about the Deployment:
-->
查看 Deployment 的详细信息:
```shell
kubectl get deployment pod-quota-demo --namespace=quota-pod-example --output=yaml
```
从输出的信息我们可以看到,尽管尝试创建三个pod,但是由于配额的限制,只有两个pod能被成功创建。
<!--
The output shows that even though the Deployment specifies three replicas, only two
Pods were created because of the quota.
-->
从输出的信息我们可以看到,尽管尝试创建三个 Pod,但是由于配额的限制,只有两个 Pod 能被成功创建。
```yaml
spec:
@@ -95,6 +130,11 @@ lastUpdateTime: 2017-07-07T20:57:05Z
exceeded quota: pod-demo, requested: pods=1, used: pods=2, limited: pods=2'
```
<!--
## Clean up
Delete your namespace:
-->
## 清理
删除命名空间:
@@ -103,36 +143,37 @@ lastUpdateTime: 2017-07-07T20:57:05Z
kubectl delete namespace quota-pod-example
```
## {{% heading "whatsnext" %}}
<!--
### For cluster administrators
### 对于集群管理
* [配置命名空间下,内存默认的request值和limit值](/docs/tasks/administer-cluster/memory-default-namespace/)
* [配置命名空间下,CPU默认的request值和limit值](/docs/tasks/administer-cluster/cpu-default-namespace/)
* [配置命名空间下,内存的最小值和最大值](/docs/tasks/administer-cluster/memory-constraint-namespace/)
* [配置命名空间下,CPU的最小值和最大值](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
* [配置命名空间下,内存和CPU的配额](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
* [配置命名空间下,API对象的配额](/docs/tasks/administer-cluster/quota-api-object/)
### 对于应用开发
* [给容器和pod分配内存资源](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [给容器和pod分配CPU资源](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [配置pod的QoS](/docs/tasks/configure-pod-container/quality-service-pod/)
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
-->
### 集群管理人员参考
* [为命名空间配置默认的内存请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)
* [为命名空间配置默认的的 CPU 请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
* [为命名空间配置内存的最小值和最大值约束](/zh/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)
* [为命名空间配置 CPU 的最小值和最大值约束](/zh/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)
* [为命名空间配置内存和 CPU 配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
* [为 API 对象的设置配额](/zh/docs/tasks/administer-cluster/quota-api-object/)
<!--
### For app developers
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
-->
### 应用开发人员参考
* [为容器和 Pod 分配内存资源](/zh/docs/tasks/configure-pod-container/assign-memory-resource/)
* [给容器和 Pod 分配 CPU 资源](/zh/docs/tasks/configure-pod-container/assign-cpu-resource/)
* [配置 Pod 的服务质量](/zh/docs/tasks/configure-pod-container/quality-service-pod/)