zh-trans: add /zh/docs/concepts/workloads/pods/podpreset.md (#11636)

zh-trans: add /zh/docs/concepts/workloads/pods/podpreset.md
This commit is contained in:
AdamDang
2018-12-10 11:11:33 +08:00
committed by Kubernetes Prow Robot
parent 4a8546a97d
commit dd566f3426
@@ -1,72 +1,151 @@
--- ---
approvers: reviewers:
- jessfraz - jessfraz
title: Pod Preset title: Pod Preset
content_template: templates/concept content_template: templates/concept
weight: 50
--- ---
{{% capture overview %}} {{% capture overview %}}
本文提供了 PodPreset 的概述。 在 pod 创建时,用户可以使用 `podpreset` 对象将特定信息注入 <!--
pod 中,这些信息可以包括 secret、 卷、卷挂载和环境变量。 This page provides an overview of PodPresets, which are objects for injecting
certain information into pods at creation time. The information can include
secrets, volumes, volume mounts, and environment variables.
-->
本文提供了 PodPreset 的概述。 在 Pod 创建时,用户可以使用 PodPreset 对象将特定信息注入 Pod 中,这些信息可以包括 secret、 卷、卷挂载和环境变量。
{{% /capture %}} {{% /capture %}}
{{< toc >}}
{{% capture body %}} {{% capture body %}}
<!--
## Understanding Pod Presets
A `Pod Preset` is an API resource for injecting additional runtime requirements
into a Pod at creation time.
You use [label selectors](/docs/concepts/overview/working-with-objects/labels/#label-selectors)
to specify the Pods to which a given Pod Preset applies.
-->
## 理解 Pod Preset ## 理解 Pod Preset
`Pod Preset` 是一种 API 资源,在 pod 创建时,用户可以用它将额外的运行时需求信息注入 pod。 `Pod Preset` 是一种 API 资源,在 Pod 创建时,用户可以用它将额外的运行时需求信息注入 Pod。
使用[标签选择器(label selector](/docs/concepts/overview/working-with-objects/labels/#label-selectors)来指定 Pod Preset 所适用的 pod。 使用[标签选择器(label selector](/docs/concepts/overview/working-with-objects/labels/#label-selectors)来指定 Pod Preset 所适用的 Pod。
使用 Pod Preset 使得 pod 模板编写者不必显式地为每个 pod 设置信息。 <!--
这样,使用特定服务的 pod 模板编写者不需要了解该服务的所有细节。 Using a Pod Preset allows pod template authors to not have to explicitly provide
all information for every pod. This way, authors of pod templates consuming a
specific service do not need to know all the details about that service.
-->
使用 Pod Preset 使得 Pod 模板编写者不必显式地为每个 Pod 设置信息。
这样,使用特定服务的 Pod 模板编写者不需要了解该服务的所有细节。
<!--
For more information about the background, see the [design proposal for PodPreset](https://git.k8s.io/community/contributors/design-proposals/service-catalog/pod-preset.md).
-->
了解更多的相关背景信息,请参考 [ PodPreset 设计提案](https://git.k8s.io/community/contributors/design-proposals/service-catalog/pod-preset.md)。 了解更多的相关背景信息,请参考 [ PodPreset 设计提案](https://git.k8s.io/community/contributors/design-proposals/service-catalog/pod-preset.md)。
<!--
## How It Works
Kubernetes provides an admission controller (`PodPreset`) which, when enabled,
applies Pod Presets to incoming pod creation requests.
When a pod creation request occurs, the system does the following:
-->
## PodPreset 如何工作 ## PodPreset 如何工作
Kubernetes 提供了准入控制器 (`PodPreset`),该控制器被启用时,会将 Pod Preset Kubernetes 提供了准入控制器 (`PodPreset`),该控制器被启用时,会将 Pod Preset
应用于接收到的 pod 创建请求中。 应用于接收到的 Pod 创建请求中。
当出现 pod 创建请求时,系统会执行以下操作: 当出现 Pod 创建请求时,系统会执行以下操作:
<!--
1. Retrieve all `PodPresets` available for use.
1. Check if the label selectors of any `PodPreset` matches the labels on the
pod being created.
1. Attempt to merge the various resources defined by the `PodPreset` into the
Pod being created.
1. On error, throw an event documenting the merge error on the pod, and create
the pod _without_ any injected resources from the `PodPreset`.
1. Annotate the resulting modified Pod spec to indicate that it has been
modified by a `PodPreset`. The annotation is of the form
`podpreset.admission.kubernetes.io/podpreset-<pod-preset name>: "<resource version>"`.
-->
1. 检索所有可用 `PodPresets` 1. 检索所有可用 `PodPresets`
1. 检查 `PodPreset` 的标签选择器与要创建的 pod 的标签是否匹配。 1. 检查 `PodPreset` 的标签选择器与要创建的 Pod 的标签是否匹配。
1. 尝试合并 `PodPreset` 中定义的各种资源,并注入要创建的 pod。 1. 尝试合并 `PodPreset` 中定义的各种资源,并注入要创建的 Pod。
1. 发生错误时抛出事件,该事件记录了 pod 信息合并错误,同时在 _不注入_ `PodPreset` 信息的情况下创建 pod。 1. 发生错误时抛出事件,该事件记录了 pod 信息合并错误,同时在 _不注入_ `PodPreset` 信息的情况下创建 Pod。
1. 为改动的 pod spec 添加注解,来表明它被 `PodPreset` 所修改。 注解形如: 1. 为改动的 Pod spec 添加注解,来表明它被 `PodPreset` 所修改。 注解形如:
`podpreset.admission.kubernetes.io/podpreset-<pod-preset name>": "<resource version>"` `podpreset.admission.kubernetes.io/podpreset-<pod-preset name>": "<resource version>"`
<!--
Each Pod can be matched by zero or more Pod Presets; and each `PodPreset` can be
applied to zero or more pods. When a `PodPreset` is applied to one or more
Pods, Kubernetes modifies the Pod Spec. For changes to `Env`, `EnvFrom`, and
`VolumeMounts`, Kubernetes modifies the container spec for all containers in
the Pod; for changes to `Volume`, Kubernetes modifies the Pod Spec.
-->
一个 Pod 可能不与任何 Pod Preset 匹配,也可能匹配多个 Pod Preset。 同时,一个 `PodPreset` 一个 Pod 可能不与任何 Pod Preset 匹配,也可能匹配多个 Pod Preset。 同时,一个 `PodPreset`
可能不应用于任何 Pod,也可能应用于多个 Pod。 当 `PodPreset` 应用于一个或多个 Pod 时,Kubernetes 可能不应用于任何 Pod,也可能应用于多个 Pod。 当 `PodPreset` 应用于一个或多个 Pod 时,Kubernetes
修改 pod spec。 对于 `Env``EnvFrom``VolumeMounts` 的改动, Kubernetes 修改 pod 修改 pod spec。 对于 `Env``EnvFrom``VolumeMounts` 的改动, Kubernetes 修改 pod
中所有容器的规格,对于卷的改动,Kubernetes 修改 Pod spec。 中所有容器的规格,对于卷的改动,Kubernetes 修改 Pod spec。
{{< note >}} {{< note >}}
**注意:** Pod Preset 能够在适当的时候修改 Pod spec 的 `spec.containers` 字段, <!--A Pod Preset is capable of modifying the `.spec.containers` field in a
但是不会应用于 `initContainers` 字段。 Pod spec when appropriate. *No* resource definition from the Pod Preset will be
applied to the `initContainers` field.-->
Pod Preset 能够在适当的时候修改 Pod spec 的 `spec.containers` 字段,但是不会应用于 `initContainers` 字段。
{{< /note >}} {{< /note >}}
<!--
### Disable Pod Preset for a Specific Pod
There may be instances where you wish for a Pod to not be altered by any Pod
Preset mutations. In these cases, you can add an annotation in the Pod Spec
of the form: `podpreset.admission.kubernetes.io/exclude: "true"`.
-->
### 为特定 Pod 禁用 Pod Preset ### 为特定 Pod 禁用 Pod Preset
在一些情况下,用户不希望 pod 被 pod preset 所改动,这时,用户可以在 pod spec 中添加形如 在一些情况下,用户不希望 Pod 被 Pod Preset 所改动,这时,用户可以在 Pod spec 中添加形如 `podpreset.admission.kubernetes.io/exclude: "true"` 的注解。
`podpreset.admission.kubernetes.io/exclude: "true"` 的注解。
<!--
## Enable Pod Preset
In order to use Pod Presets in your cluster you must ensure the following:
-->
## 启用 Pod Preset ## 启用 Pod Preset
为了在集群中使用 Pod Preset,必须确保以下几点: 为了在集群中使用 Pod Preset,必须确保以下几点:
1. 已启用 api 类型 `settings.k8s.io/v1alpha1/podpreset`。 这可以通过在 API 服务器的 <!--
`--runtime-config` 配置项中包含 `settings.k8s.io/v1alpha1=true` 来实现。 1. You have enabled the API type `settings.k8s.io/v1alpha1/podpreset`. For
1. 已启用准入控制器 `PodPreset`。 启用的一种方式是在 API 服务器的 `--admission-control` example, this can be done by including `settings.k8s.io/v1alpha1=true` in
配置项中包含 `PodPreset` the `--runtime-config` option for the API server.
1. 已经通过在相应的名字空间中创建 `PodPreset` 对象,定义了 Pod preset。 1. You have enabled the admission controller `PodPreset`. One way to doing this
is to include `PodPreset` in the `--enable-admission-plugins` option value specified
for the API server.
1. You have defined your Pod Presets by creating `PodPreset` objects in the
namespace you will use.
-->
1. 已启用 API 类型 `settings.k8s.io/v1alpha1/podpreset`。 这可以通过在 API 服务器的 `--runtime-config` 配置项中包含 `settings.k8s.io/v1alpha1=true` 来实现。
1. 已启用准入控制器 `PodPreset`。 启用的一种方式是在 API 服务器的 `--admission-control` 配置项中包含 `PodPreset`
1. 已经通过在相应的命名空间中创建 `PodPreset` 对象,定义了 Pod Preset。
{{% /capture %}} {{% /capture %}}
{{% capture whatsnext %}} {{% capture whatsnext %}}
<!--
* [使用 PodPreset 将信息注入 Pods](/docs/tasks/inject-data-application/podpreset/) * [Injecting data into a Pod using PodPreset](/docs/tasks/inject-data-application/podpreset/)
-->
* [使用 PodPreset 将信息注入 Pod](/docs/tasks/inject-data-application/podpreset/)
{{% /capture %}} {{% /capture %}}