Skip to content

Commit

Permalink
[zh] Sync scheduling-hugepages.md
Browse files Browse the repository at this point in the history
  • Loading branch information
windsonsea committed Oct 25, 2023
1 parent d7e023e commit 83d7c2e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 42 deletions.
68 changes: 52 additions & 16 deletions content/zh-cn/docs/tasks/manage-hugepages/scheduling-hugepages.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 管理巨页(HugePages
title: 管理巨页(HugePage
content_type: task
description: 将大页配置和管理为集群中的可调度资源。
description: 将巨页作为集群中的可调度资源来配置和管理
---
<!--
reviewers:
Expand All @@ -12,6 +12,7 @@ description: Configure and manage huge pages as a schedulable resource in a clus
--->

<!-- overview -->

{{< feature-state state="stable" >}}

<!--
Expand All @@ -20,24 +21,62 @@ by applications in a Pod. This page describes how users can consume huge pages.
--->
Kubernetes 支持在 Pod 应用中使用预先分配的巨页。本文描述了用户如何使用巨页,以及当前的限制。

## {{% heading "prerequisites" %}}

<!--
Kubernetes nodes must
[pre-allocate huge pages](https://www.kernel.org/doc/html/latest/admin-guide/mm/hugetlbpage.html)
in order for the node to report its huge page capacity.
## {{% heading "prerequisites" %}}
A node can pre-allocate huge pages for multiple sizes, for instance,
the following line in `/etc/default/grub` allocates `2*1GiB` of 1 GiB
and `512*2 MiB` of 2 MiB pages:
--->
为了使节点能够上报巨页容量,Kubernetes
节点必须[预先分配巨页](https://www.kernel.org/doc/html/latest/admin-guide/mm/hugetlbpage.html)

节点能够预先分配多种规格的巨页。例如,在 `/etc/default/grub`
中的以下这一行分配了 `2*1GiB` 的 1 GiB 页面和 `512*2 MiB` 的 2 MiB 页面。

<!--
1. Kubernetes nodes must pre-allocate huge pages in order for the node to report
its huge page capacity. A node can pre-allocate huge pages for multiple
sizes.
```
GRUB_CMDLINE_LINUX="hugepagesz=1G hugepages=2 hugepagesz=2M hugepages=512"
```

<!--
The nodes will automatically discover and report all huge page resources as
schedulable resources.
--->
1. 为了使节点能够上报巨页容量,Kubernetes 节点必须预先分配巨页。每个节点能够预先分配多种规格的巨页。
节点会自动发现全部巨页资源,并作为可供调度的资源进行上报。
When you describe the Node, you should see something similar to the following
in the following in the `Capacity` and `Allocatable` sections:
-->
节点将自动发现并报告所有巨页资源作为可调度资源。

当你描述 Node 时,你应该在 `Capacity``Allocatable` 节中看到类似以下内容:

```
Capacity:
cpu: ...
ephemeral-storage: ...
hugepages-1Gi: 2Gi
hugepages-2Mi: 1Gi
memory: ...
pods: ...
Allocatable:
cpu: ...
ephemeral-storage: ...
hugepages-1Gi: 2Gi
hugepages-2Mi: 1Gi
memory: ...
pods: ...
```

{{< note >}}
<!--
For dynamically allocated pages (after boot), the Kubelet needs to be restarted
for the new allocations to be refrelected.
-->
对于动态分配的页面(引导后),kubelet 需要被重新启动才能更新为新的分配。
{{< /note >}}

<!-- steps -->

Expand All @@ -55,7 +94,6 @@ memory or CPU resources must be requested as well.
A pod may consume multiple huge page sizes in a single pod spec. In this case it
must use `medium: HugePages-<hugepagesize>` notation for all volume mounts.
--->

用户可以通过在容器级别的资源需求中使用资源名称 `hugepages-<size>`
来使用巨页,其中的 size 是特定节点上支持的以整数值表示的最小二进制单位。
例如,如果一个节点支持 2048KiB 和 1048576KiB 页面大小,它将公开可调度的资源
Expand Down Expand Up @@ -97,6 +135,7 @@ spec:
emptyDir:
medium: HugePages-1Gi
```
<!--
A pod may use `medium: HugePages` only if it requests huge pages of one size.
-->
Expand Down Expand Up @@ -144,12 +183,9 @@ spec:
--->

- 巨页的资源请求值必须等于其限制值。该条件在指定了资源限制,而没有指定请求的情况下默认成立。
- 巨页是被隔离在 pod 作用域的,因此每个容器在 spec 中都对 cgroup 沙盒有自己的限制。
- 巨页是被隔离在 Pod 作用域的,因此每个容器在 spec 中都对 cgroup 沙盒有自己的限制。
- 巨页可用于 EmptyDir 卷,不过 EmptyDir 卷所使用的巨页数量不能够超出 Pod 请求的巨页数量。
- 通过带有 `SHM_HUGETLB` 的 `shmget()` 使用巨页的应用,必须运行在一个与
`proc/sys/vm/hugetlb_shm_group` 匹配的补充组下。
`proc/sys/vm/hugetlb_shm_group` 匹配的补充组下。
- 通过 ResourceQuota 资源,可以使用 `hugepages-<size>` 标记控制每个命名空间下的巨页使用量,
类似于使用 `cpu` 或 `memory` 来控制其他计算资源。



Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This document explains how to define and manage objects using configuration file
<!--
Install [`kubectl`](/docs/tasks/tools/).
-->
安装 [`kubectl`](/zh-cn/docs/tasks/tools/)
安装 [`kubectl`](/zh-cn/docs/tasks/tools/)

{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}

Expand All @@ -34,7 +34,7 @@ Install [`kubectl`](/docs/tasks/tools/).
The `kubectl` tool supports three kinds of object management:
-->
## 权衡
## 权衡 {#trade-offs}

`kubectl` 工具支持三种对象管理:

Expand All @@ -51,7 +51,7 @@ The `kubectl` tool supports three kinds of object management:
See [Kubernetes Object Management](/docs/concepts/overview/working-with-objects/object-management/)
for a discussion of the advantages and disadvantage of each kind of object management.
-->
参看 [Kubernetes 对象管理](/zh-cn/docs/concepts/overview/working-with-objects/object-management/)
参见 [Kubernetes 对象管理](/zh-cn/docs/concepts/overview/working-with-objects/object-management/)
中关于每种对象管理的优缺点的讨论。

<!--
Expand All @@ -61,16 +61,20 @@ You can use `kubectl create -f` to create an object from a configuration file.
Refer to the [kubernetes API reference](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/)
for details.
-->
## 如何创建对象
## 如何创建对象 {#how-to-create-objects}

你可以使用 `kubectl create -f` 从配置文件创建一个对象。
请参考 [kubernetes API 参考](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/) 有关详细信息
更多细节参阅 [kubernetes API 参考](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/)。

* `kubectl create -f <filename|url>`

<!--
## How to update objects
-->
## 如何更新对象 {#how-to-update-objects}

{{< warning >}}
<!--
Updating objects with the `replace` command drops all
parts of the spec not specified in the configuration file. This
should not be used with objects whose specs are partially managed
Expand All @@ -79,9 +83,6 @@ the `externalIPs` field is managed independently from the configuration
file. Independently managed fields must be copied to the configuration
file to prevent `replace` from dropping them.
-->
## 如何更新对象

{{< warning >}}
使用 `replace` 命令更新对象会删除所有未在配置文件中指定的规范的某些部分。
不应将其规范由集群部分管理的对象使用,比如类型为 `LoadBalancer` 的服务,
其中 `externalIPs` 字段独立于配置文件进行管理。
Expand All @@ -92,7 +93,7 @@ file to prevent `replace` from dropping them.
You can use `kubectl replace -f` to update a live object according to a
configuration file.
-->
你可以使用 `kubectl replace -f` 根据配置文件更新活动对象。
你可以使用 `kubectl replace -f` 根据配置文件更新活动对象。

* `kubectl replace -f <filename|url>`

Expand All @@ -102,24 +103,19 @@ configuration file.
You can use `kubectl delete -f` to delete an object that is described in a
configuration file.
-->
## 如何删除对象
## 如何删除对象 {#how-to-delete-objects}

你可以使用 `kubectl delete -f` 删除配置文件中描述的对象。

* `kubectl delete -f <filename|url>`

{{< note >}}
<!--
If configuration file has specified the `generateName` field in the `metadata`
section instead of the `name` field, you cannot delete the object using
`kubectl delete -f <filename|url>`.
You will have to use other flags for deleting the object. For example:
```shell
kubectl delete <type> <name>
kubectl delete <type> -l <label>
```
-->
{{< note >}}
如果配置文件在 `metadata` 节中设置了 `generateName` 字段而非 `name` 字段,
你无法使用 `kubectl delete -f <filename|url>` 来删除该对象。
你必须使用其他标志才能删除对象。例如:
Expand All @@ -136,7 +132,7 @@ kubectl delete <type> -l <label>
You can use `kubectl get -f` to view information about an object that is
described in a configuration file.
-->
## 如何查看对象
## 如何查看对象 {#how-to-view-an-object}

你可以使用 `kubectl get -f` 查看有关配置文件中描述的对象的信息。

Expand All @@ -146,8 +142,7 @@ described in a configuration file.
The `-o yaml` flag specifies that the full object configuration is printed.
Use `kubectl get -h` to see a list of options.
-->
`-o yaml` 标志指定打印完整的对象配置。
使用 `kubectl get -h` 查看选项列表。
`-o yaml` 标志指定打印完整的对象配置。使用 `kubectl get -h` 查看选项列表。

<!--
## Limitations
Expand All @@ -160,7 +155,7 @@ is executed. This can happen if a controller, such as
a HorizontalPodAutoscaler, makes updates directly to a live object. Here's
an example:
-->
## 局限性
## 局限性 {#limitations}

当完全定义每个对象的配置并将其记录在其配置文件中时,`create``replace``delete` 命令会很好的工作。
但是,当更新一个活动对象,并且更新没有合并到其配置文件中时,下一次执行 `replace` 时,更新将丢失。
Expand Down Expand Up @@ -191,7 +186,7 @@ Suppose you have the URL of an object configuration file. You can use
object is created. This is particularly useful for tutorials and tasks
that point to a configuration file that could be modified by the reader.
-->
## 从 URL 创建和编辑对象而不保存配置
## 从 URL 创建和编辑对象而不保存配置 {#creating-and-editing-an-object-from-a-url-without-saving-the-configuration}

假设你具有对象配置文件的 URL。
你可以在创建对象之前使用 `kubectl create --edit` 对配置进行更改。
Expand All @@ -207,7 +202,7 @@ kubectl create -f <url> --edit
Migrating from imperative commands to imperative object configuration involves
several manual steps.
-->
## 从命令式命令迁移到命令式对象配置
## 从命令式命令迁移到命令式对象配置 {#migrating-from-imperative-commands-to-imperative-object-configuration}

从命令式命令迁移到命令式对象配置涉及几个手动步骤。

Expand Down Expand Up @@ -237,12 +232,12 @@ several manual steps.
<!--
## Defining controller selectors and PodTemplate labels
-->
## 定义控制器选择器和 PodTemplate 标签
## 定义控制器选择器和 PodTemplate 标签 {#defining-controller-selectors-and-podtemplate-labels}

{{< warning >}}
<!--
Updating selectors on controllers is strongly discouraged.
-->
{{< warning >}}
不建议在控制器上更新选择器。
{{< /warning >}}

Expand Down Expand Up @@ -279,5 +274,3 @@ template:
* [使用配置文件对 Kubernetes 对象进行声明式管理](/zh-cn/docs/tasks/manage-kubernetes-objects/declarative-config/)
* [Kubectl 命令参考](/docs/reference/generated/kubectl/kubectl-commands/)
* [Kubernetes API 参考](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/)

0 comments on commit 83d7c2e

Please sign in to comment.