[zh-cn]sync kustomization.md
Signed-off-by: xin.li <xin.li@daocloud.io>
This commit is contained in:
parent
b9fec59288
commit
16335109b2
|
|
@ -539,8 +539,10 @@ cat <<EOF >./kustomization.yaml
|
|||
namespace: my-namespace
|
||||
namePrefix: dev-
|
||||
nameSuffix: "-001"
|
||||
commonLabels:
|
||||
app: bingo
|
||||
labels:
|
||||
- pairs:
|
||||
app: bingo
|
||||
includeSelectors: true
|
||||
commonAnnotations:
|
||||
oncallPager: 800-555-1212
|
||||
resources:
|
||||
|
|
@ -660,17 +662,28 @@ The Resources from `kubectl kustomize ./` contain both the Deployment and the Se
|
|||
#### Customizing
|
||||
|
||||
Patches can be used to apply different customizations to Resources. Kustomize supports different patching
|
||||
mechanisms through `patchesStrategicMerge` and `patchesJson6902`. `patchesStrategicMerge` is a list of file paths. Each file should be resolved to a [strategic merge patch](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md). The names inside the patches must match Resource names that are already loaded. Small patches that do one thing are recommended. For example, create one patch for increasing the deployment replica number and another patch for setting the memory limit.
|
||||
mechanisms through `StrategicMerge` and `Json6902` using the `patches` field. `patches` may be a file or
|
||||
an inline string, targeting a single or multiple resources.
|
||||
-->
|
||||
#### 定制 {#customizing}
|
||||
|
||||
补丁文件(Patches)可以用来对资源执行不同的定制。
|
||||
Kustomize 通过 `patchesStrategicMerge` 和 `patchesJson6902` 支持不同的打补丁机制。
|
||||
`patchesStrategicMerge` 的内容是一个文件路径的列表,其中每个文件都应可解析为
|
||||
[策略性合并补丁(Strategic Merge Patch)](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md)。
|
||||
补丁文件中的名称必须与已经加载的资源的名称匹配。
|
||||
建议构造规模较小的、仅做一件事情的补丁。
|
||||
例如,构造一个补丁来增加 Deployment 的副本个数;构造另外一个补丁来设置内存限制。
|
||||
Kustomize 通过 `StrategicMerge` 和 `Json6902` 使用 `patches` 字段支持不同的打补丁机制。
|
||||
|
||||
<!--
|
||||
The `patches` field contains a list of patches applied in the order they are specified. The patch target
|
||||
selects resources by `group`, `version`, `kind`, `name`, `namespace`, `labelSelector` and `annotationSelector`.
|
||||
|
||||
Small patches that do one thing are recommended. For example, create one patch for increasing the deployment
|
||||
replica number and another patch for setting the memory limit. The target resource is matched using `group`, `version`,
|
||||
`kind`, and `name` fields from the patch file.
|
||||
-->
|
||||
`patches` 字段包含了一列按指定顺序应用的补丁。
|
||||
补丁目标通过 `group`、`version`、`kind`、`name`、`namespace`、`labelSelector` 和
|
||||
`annotationSelector` 来选择资源。
|
||||
|
||||
建议使用只做一件事的小补丁。例如,创建一个用于增加部署副本数量的补丁,以及另一个用于设置内存限制的补丁。
|
||||
目标资源是通过补丁文件中的 `group`、`version`、`kind` 和 `name` 字段进行匹配的。
|
||||
|
||||
```shell
|
||||
# 创建 deployment.yaml 文件
|
||||
|
|
@ -725,9 +738,9 @@ EOF
|
|||
cat <<EOF >./kustomization.yaml
|
||||
resources:
|
||||
- deployment.yaml
|
||||
patchesStrategicMerge:
|
||||
- increase_replicas.yaml
|
||||
- set_memory.yaml
|
||||
patches:
|
||||
- path: increase_replicas.yaml
|
||||
- path: set_memory.yaml
|
||||
EOF
|
||||
```
|
||||
|
||||
|
|
@ -762,17 +775,20 @@ spec:
|
|||
```
|
||||
|
||||
<!--
|
||||
Not all Resources or fields support strategic merge patches. To support modifying arbitrary fields in arbitrary Resources,
|
||||
Kustomize offers applying [JSON patch](https://tools.ietf.org/html/rfc6902) through `patchesJson6902`.
|
||||
To find the correct Resource for a Json patch, the group, version, kind and name of that Resource need to be
|
||||
specified in `kustomization.yaml`. For example, increasing the replica number of a Deployment object can also be done
|
||||
through `patchesJson6902`.
|
||||
Not all Resources or fields support `strategicMerge` patches. To support modifying arbitrary fields in arbitrary Resources,
|
||||
Kustomize offers applying [JSON patch](https://tools.ietf.org/html/rfc6902) through `Json6902`.
|
||||
To find the correct Resource for a `Json6902` patch, it is mandatory to specify the `target` field in `kustomization.yaml`.
|
||||
-->
|
||||
并非所有资源或者字段都支持策略性合并补丁。为了支持对任何资源的任何字段进行修改,
|
||||
Kustomize 提供通过 `patchesJson6902` 来应用 [JSON 补丁](https://tools.ietf.org/html/rfc6902)的能力。
|
||||
为了给 JSON 补丁找到正确的资源,需要在 `kustomization.yaml` 文件中指定资源的组(group)、
|
||||
版本(version)、类别(kind)和名称(name)。
|
||||
例如,为某 Deployment 对象增加副本个数的操作也可以通过 `patchesJson6902` 来完成:
|
||||
并非所有资源或者字段都支持策略性合并(`strategicMerge`)补丁。为了支持对任何资源的任何字段进行修改,
|
||||
Kustomize 提供通过 `Json6902` 来应用 [JSON 补丁](https://tools.ietf.org/html/rfc6902)的能力。
|
||||
为了给 `Json6902` 补丁找到正确的资源,必须在 `kustomization.yaml` 文件中设置 `target` 字段。
|
||||
|
||||
<!--
|
||||
For example, increasing the replica number of a Deployment object can also be done through `Json6902` patch. The target resource
|
||||
is matched using `group`, `version`, `kind`, and `name` from the `target` field.
|
||||
-->
|
||||
例如,可以通过 `Json6902` 补丁来增加 Deployment 对象的副本数量。
|
||||
目标资源是通过 `target` 字段中的 `group`、`version`、`kind` 和 `name` 进行匹配的。
|
||||
|
||||
```shell
|
||||
# 创建一个 deployment.yaml 文件
|
||||
|
|
@ -810,7 +826,7 @@ cat <<EOF >./kustomization.yaml
|
|||
resources:
|
||||
- deployment.yaml
|
||||
|
||||
patchesJson6902:
|
||||
patches:
|
||||
- target:
|
||||
group: apps
|
||||
version: v1
|
||||
|
|
@ -849,7 +865,8 @@ spec:
|
|||
|
||||
<!--
|
||||
In addition to patches, Kustomize also offers customizing container images or injecting field values from other objects into containers
|
||||
without creating patches. For example, you can change the image used inside containers by specifying the new image in `images` field in `kustomization.yaml`.
|
||||
without creating patches. For example, you can change the image used inside containers by specifying the new image in the `images` field
|
||||
in `kustomization.yaml`.
|
||||
-->
|
||||
除了补丁之外,Kustomize 还提供定制容器镜像或者将其他对象的字段值注入到容器中的能力,并且不需要创建补丁。
|
||||
例如,你可以通过在 `kustomization.yaml` 文件的 `images` 字段设置新的镜像来更改容器中使用的镜像。
|
||||
|
|
@ -918,14 +935,15 @@ spec:
|
|||
Sometimes, the application running in a Pod may need to use configuration values from other objects. For example,
|
||||
a Pod from a Deployment object need to read the corresponding Service name from Env or as a command argument.
|
||||
Since the Service name may change as `namePrefix` or `nameSuffix` is added in the `kustomization.yaml` file. It is
|
||||
not recommended to hard code the Service name in the command argument. For this usage, Kustomize can inject the Service name into containers through `vars`.
|
||||
not recommended to hard code the Service name in the command argument. For this usage, Kustomize can inject
|
||||
the Service name into containers through `replacements`.
|
||||
-->
|
||||
有些时候,Pod 中运行的应用可能需要使用来自其他对象的配置值。
|
||||
例如,某 Deployment 对象的 Pod 需要从环境变量或命令行参数中读取读取
|
||||
Service 的名称。
|
||||
由于在 `kustomization.yaml` 文件中添加 `namePrefix` 或 `nameSuffix` 时
|
||||
Service 名称可能发生变化,建议不要在命令参数中硬编码 Service 名称。
|
||||
对于这种使用场景,Kustomize 可以通过 `vars` 将 Service 名称注入到容器中。
|
||||
对于这种使用场景,Kustomize 可以通过 `replacements` 将 Service 名称注入到容器中。
|
||||
|
||||
```shell
|
||||
# 创建一个 deployment.yaml 文件(引用此处的文档分隔符)
|
||||
|
|
@ -947,7 +965,7 @@ spec:
|
|||
containers:
|
||||
- name: my-nginx
|
||||
image: nginx
|
||||
command: ["start", "--host", "$(MY_SERVICE_NAME)"]
|
||||
command: ["start", "--host", "MY_SERVICE_NAME_PLACEHOLDER"]
|
||||
EOF
|
||||
|
||||
# 创建一个 service.yaml 文件
|
||||
|
|
@ -974,12 +992,17 @@ resources:
|
|||
- deployment.yaml
|
||||
- service.yaml
|
||||
|
||||
vars:
|
||||
- name: MY_SERVICE_NAME
|
||||
objref:
|
||||
replacements:
|
||||
- source:
|
||||
kind: Service
|
||||
name: my-nginx
|
||||
apiVersion: v1
|
||||
fieldPath: metadata.name
|
||||
targets:
|
||||
- select:
|
||||
kind: Deployment
|
||||
name: my-nginx
|
||||
fieldPaths:
|
||||
- spec.template.spec.containers.0.command.2
|
||||
EOF
|
||||
```
|
||||
|
||||
|
|
@ -1019,8 +1042,10 @@ Kustomize has the concepts of **bases** and **overlays**. A **base** is a direct
|
|||
set of resources and associated customization. A base could be either a local directory or a directory from a remote repo,
|
||||
as long as a `kustomization.yaml` is present inside. An **overlay** is a directory with a `kustomization.yaml` that refers to other
|
||||
kustomization directories as its `bases`. A **base** has no knowledge of an overlay and can be used in multiple overlays.
|
||||
An overlay may have multiple bases and it composes all resources
|
||||
from bases and may also have customization on top of them.
|
||||
|
||||
The `kustomization.yaml` in a **overlay** directory may refer to multiple `bases`, combining all the resources defined
|
||||
in these bases into a unified configuration. Additionally, it can apply customizations on top of these resources to meet specific
|
||||
requirements.
|
||||
|
||||
Here is an example of a base:
|
||||
-->
|
||||
|
|
@ -1032,7 +1057,12 @@ Kustomize 中有 **基准(bases)** 和 **覆盖(overlays)** 的概念区
|
|||
**覆盖** 也是一个目录,其中包含将其他 kustomization 目录当做 `bases` 来引用的
|
||||
`kustomization.yaml` 文件。
|
||||
**基准**不了解覆盖的存在,且可被多个覆盖所使用。
|
||||
覆盖则可以有多个基准,且可针对所有基准中的资源执行组织操作,还可以在其上执行定制。
|
||||
|
||||
`kustomization.yaml` 文件位于 **overlay** 目录中,可以引用多个 `bases`,
|
||||
将这些 base 中定义的所有资源合并为一个统一的配置。
|
||||
此外,它还可以在这些资源之上应用定制化修改以满足特定需求。
|
||||
|
||||
以下是 base 的一个示例:
|
||||
|
||||
```shell
|
||||
# 创建一个包含基准的目录
|
||||
|
|
@ -1152,8 +1182,10 @@ EOF
|
|||
# 创建 kustomization.yaml
|
||||
cat <<EOF >./kustomization.yaml
|
||||
namePrefix: dev-
|
||||
commonLabels:
|
||||
app: my-nginx
|
||||
labels:
|
||||
- pairs:
|
||||
app: my-nginx
|
||||
includeSelectors: true
|
||||
resources:
|
||||
- deployment.yaml
|
||||
EOF
|
||||
|
|
@ -1209,42 +1241,44 @@ deployment.apps "dev-my-nginx" deleted
|
|||
<!--
|
||||
| Field | Type | Explanation |
|
||||
|-----------------------|--------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
|
||||
| namespace | string | add namespace to all resources |
|
||||
| namePrefix | string | value of this field is prepended to the names of all resources |
|
||||
| nameSuffix | string | value of this field is appended to the names of all resources |
|
||||
| commonLabels | map[string]string | labels to add to all resources and selectors |
|
||||
| commonAnnotations | map[string]string | annotations to add to all resources |
|
||||
| resources | []string | each entry in this list must resolve to an existing resource configuration file |
|
||||
| configMapGenerator | [][ConfigMapArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/configmapargs.go#L7) | Each entry in this list generates a ConfigMap |
|
||||
| secretGenerator | [][SecretArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/secretargs.go#L7) | Each entry in this list generates a Secret |
|
||||
| generatorOptions | [GeneratorOptions](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/generatoroptions.go#L7) | Modify behaviors of all ConfigMap and Secret generator |
|
||||
| bases | []string | Each entry in this list should resolve to a directory containing a kustomization.yaml file |
|
||||
| patchesStrategicMerge | []string | Each entry in this list should resolve a strategic merge patch of a Kubernetes object |
|
||||
| patchesJson6902 | [][Patch](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/patch.go#L10) | Each entry in this list should resolve to a Kubernetes object and a Json Patch |
|
||||
| vars | [][Var](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/var.go#L19) | Each entry is to capture text from one resource's field |
|
||||
| images | [][Image](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/image.go#L8) | Each entry is to modify the name, tags and/or digest for one image without creating patches |
|
||||
| commonAnnotations | map[string]string | annotations to add to all resources |
|
||||
| commonLabels | map[string]string | labels to add to all resources and selectors |
|
||||
| configMapGenerator | [][ConfigMapArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/configmapargs.go#L7) | Each entry in this list generates a ConfigMap |
|
||||
| configurations | []string | Each entry in this list should resolve to a file containing [Kustomize transformer configurations](https://github.com/kubernetes-sigs/kustomize/tree/master/examples/transformerconfigs) |
|
||||
| crds | []string | Each entry in this list should resolve to an OpenAPI definition file for Kubernetes types |
|
||||
| generatorOptions | [GeneratorOptions](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/generatoroptions.go#L7) | Modify behaviors of all ConfigMap and Secret generator |
|
||||
| images | [][Image](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/image.go#L8) | Each entry is to modify the name, tags and/or digest for one image without creating patches |
|
||||
| labels | map[string]string | Add labels without automically injecting corresponding selectors |
|
||||
| namePrefix | string | value of this field is prepended to the names of all resources |
|
||||
| nameSuffix | string | value of this field is appended to the names of all resources |
|
||||
| patchesJson6902 | [][Patch](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/patch.go#L10) | Each entry in this list should resolve to a Kubernetes object and a Json Patch |
|
||||
| patchesStrategicMerge | []string | Each entry in this list should resolve a strategic merge patch of a Kubernetes object |
|
||||
| replacements | [][Replacements](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/replacement.go#L15) | copy the value from a resource's field into any number of specified targets.
|
||||
| resources | []string | each entry in this list must resolve to an existing resource configuration file |
|
||||
| secretGenerator | [][SecretArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/secretargs.go#L7) | Each entry in this list generates a Secret |
|
||||
| vars | [][Var](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/var.go#L19) | Each entry is to capture text from one resource's field |
|
||||
-->
|
||||
|
||||
| 字段 | 类型 | 解释 |
|
||||
|-----------------------|--------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
|
||||
| namespace | string | 为所有资源添加名字空间 |
|
||||
| namePrefix | string | 此字段的值将被添加到所有资源名称前面 |
|
||||
| nameSuffix | string | 此字段的值将被添加到所有资源名称后面 |
|
||||
| commonLabels | map[string]string | 要添加到所有资源和选择算符的标签 |
|
||||
| commonAnnotations | map[string]string | 要添加到所有资源的注解 |
|
||||
| resources | []string | 列表中的每个条目都必须能够解析为现有的资源配置文件 |
|
||||
| configMapGenerator | [][ConfigMapArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/configmapargs.go#L7) | 列表中的每个条目都会生成一个 ConfigMap |
|
||||
| secretGenerator | [][SecretArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/secretargs.go#L7) | 列表中的每个条目都会生成一个 Secret |
|
||||
| generatorOptions | [GeneratorOptions](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/generatoroptions.go#L7) | 更改所有 ConfigMap 和 Secret 生成器的行为 |
|
||||
| bases | []string | 列表中每个条目都应能解析为一个包含 kustomization.yaml 文件的目录 |
|
||||
| patchesStrategicMerge | []string | 列表中每个条目都能解析为某 Kubernetes 对象的策略性合并补丁 |
|
||||
| patchesJson6902 | [][Patch](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/patch.go#L10) | 列表中每个条目都能解析为一个 Kubernetes 对象和一个 JSON 补丁 |
|
||||
| vars | [][Var](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/var.go#L19) | 每个条目用来从某资源的字段来析取文字 |
|
||||
| images | [][Image](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/image.go#L8) | 每个条目都用来更改镜像的名称、标记与/或摘要,不必生成补丁 |
|
||||
| commonAnnotations | map[string]string | 要添加到所有资源的注解 |
|
||||
| commonLabels | map[string]string | 要添加到所有资源和选择算符的标签 |
|
||||
| configMapGenerator | [][ConfigMapArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/configmapargs.go#L7) | 列表中的每个条目都会生成一个 ConfigMap |
|
||||
| configurations | []string | 列表中每个条目都应能解析为一个包含 [Kustomize 转换器配置](https://github.com/kubernetes-sigs/kustomize/tree/master/examples/transformerconfigs) 的文件 |
|
||||
| crds | []string | 列表中每个条目都应能够解析为 Kubernetes 类别的 OpenAPI 定义文件 |
|
||||
| generatorOptions | [GeneratorOptions](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/generatoroptions.go#L7) | 更改所有 ConfigMap 和 Secret 生成器的行为 |
|
||||
| images | [][Image](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/image.go#L8) | 每个条目都用来更改镜像的名称、标记与/或摘要,不必生成补丁 |
|
||||
| labels | map[string]string | 添加标签而不自动注入对应的选择器 |
|
||||
| namePrefix | string | 此字段的值将被添加到所有资源名称前面 |
|
||||
| nameSuffix | string | 此字段的值将被添加到所有资源名称后面 |
|
||||
| patchesJson6902 | [][Patch](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/patch.go#L10) | 列表中每个条目都能解析为一个 Kubernetes 对象和一个 JSON 补丁 |
|
||||
| patchesStrategicMerge | []string | 列表中每个条目都能解析为某 Kubernetes 对象的策略性合并补丁 |
|
||||
| replacements | [][Replacements](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/replacement.go#L15) | 将 resource 字段的值复制到任意数量的指定目标
|
||||
| resources | []string | 列表中的每个条目都必须能够解析为现有的资源配置文件 |
|
||||
| secretGenerator | [][SecretArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/secretargs.go#L7) | 列表中的每个条目都会生成一个 Secret |
|
||||
| vars | [][Var](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/var.go#L19) | 每个条目用来从某资源的字段来析取文字 |
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue