add zh docsy

This commit is contained in:
guoxudong
2020-06-15 13:39:13 +08:00
parent a0072a2cf9
commit 518147c129
240 changed files with 49830 additions and 1083 deletions

View File

@@ -0,0 +1,11 @@
---
title: "kustomization.yaml"
linkTitle: "kustomization.yaml"
type: docs
weight: 10
description: >
kustomization.yaml fields and API
---

View File

@@ -0,0 +1,13 @@
---
title: "bases"
linkTitle: "bases"
type: docs
description: >
在 Kustomization 目录中添加资源。
---
{{% pageinfo color="warning" %}}
`bases` 字段在 v2.1.0 中已被弃用。
{{% /pageinfo %}}
该条目已被移动到 [resources](/kustomize/zh/api-reference/kustomization/resource) 字段中,其仍是[核心概念](/kustomize/zh/api-reference/kustomization/glossary#base),这使得相对于其他输入资源 base 可以进行排序。

View File

@@ -0,0 +1,56 @@
---
title: "commonAnnotations"
linkTitle: "commonAnnotations"
type: docs
description: >
为所有字段添加注释。
---
为所有资源添加注释,如果资源上已经存在注解键,该值将被覆盖。
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonAnnotations:
oncallPager: 800-555-1212
```
## Example
### 输入文件
```yaml
# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonAnnotations:
oncallPager: 800-555-1212
resources:
- deploy.yaml
```
```yaml
# deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: example
spec:
...
```
### 构建输出
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: example
annotations:
oncallPager: 800-555-1212
spec:
...
```

View File

@@ -0,0 +1,99 @@
---
title: "commonLabels"
linkTitle: "commonLabels"
type: docs
description: >
为所有资源和 selectors 增加标签。
---
为所有资源和 selectors 增加标签。如果资源上已经存在注解键,该值将被覆盖。
{{% pageinfo color="warning" %}}
一旦将资源应用于集群,就不应更改诸如 Deployments 和 Services 之类的资源选择器。
将 commonLabels 更改为可变资源可能会导致部署失败。
{{% /pageinfo %}}
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonLabels:
someName: someValue
owner: alice
app: bingo
```
## Example
### 文件输入
```yaml
# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonLabels:
someName: someValue
owner: alice
app: bingo
resources:
- deploy.yaml
- service.yaml
```
```yaml
# deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: example
```
```yaml
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: example
```
### 构建输出
```yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: bingo
owner: alice
someName: someValue
name: example
spec:
selector:
app: bingo
owner: alice
someName: someValue
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: bingo
owner: alice
someName: someValue
name: example
spec:
selector:
matchLabels:
app: bingo
owner: alice
someName: someValue
template:
metadata:
labels:
app: bingo
owner: alice
someName: someValue
```

View File

@@ -0,0 +1,9 @@
---
title: "components"
linkTitle: "components"
type: docs
description: >
Compose kustomizations.
---
*Coming soon*

View File

@@ -0,0 +1,64 @@
---
title: "configMapGenerator"
linkTitle: "configMapGenerator"
type: docs
description: >
生成 ConfigMap 资源.
---
列表中的每个条目都将生成一个 ConfigMap (合计可以生成 n 个 ConfigMap
下面的示例会生成 3 个ConfigMap第一个带有给定文件的名称和内容第二个将在 data 中添加 key/value第三个通过 `options` 为单个 ConfigMap 设置注释和标签。
每个 configMapGenerator 项均接受的参数 `behavior: [create|replace|merge]`,这个参数允许修改或替换父级现有的 configMap。
此外,每个条目都有一个 `options` 字段,该字段具有与 kustomization 文件的 `generatorOptions` 字段相同的子字段。
`options` 字段允许用户为生成的实例添加标签和(或)注释,或者分别禁用该实例名称的哈希后缀。此处添加的标签和注释不会被 kustomization 文件 `generatorOptions` 字段关联的全局选项覆盖。但是如果全局 `generatorOptions` 字段指定 `disableNameSuffixHash: true`,其他 `options` 的设置将无法将其覆盖。
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
# 这个标签将添加到所有的 ConfigMap 和 Secret 中。
generatorOptions:
labels:
fruit: apple
configMapGenerator:
- name: my-java-server-props
behavior: merge
files:
- application.properties
- more.properties
- name: my-java-server-env-vars
literals:
- JAVA_HOME=/opt/java/jdk
- JAVA_TOOL_OPTIONS=-agentlib:hprof
options:
disableNameSuffixHash: true
labels:
pet: dog
- name: dashboards
files:
- mydashboard.json
options:
annotations:
dashboard: "1"
labels:
app.kubernetes.io/name: "app1"
```
这里也可以[定义一个 key](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-the-key-to-use-when-creating-a-configmap-from-a-file) 来为文件设置不同名称。
下面这个示例会创建一个 ConfigMap并将 `whatever.ini` 重命名为 `myFileName.ini`
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
- name: app-whatever
files:
- myFileName.ini=whatever.ini
```

View File

@@ -0,0 +1,34 @@
---
title: "crds"
linkTitle: "crds"
type: docs
description: >
增加对 CRD 的支持。
---
此列表中的每个条目都应该是自定义资源定义CRD文件的相对路径。
该字段的存在是为了让 kustomize 识别用户自定义的 CRD ,并对这些类型中的对象应用适当的转换。
典型用例CRD 引用 ConfigMap 对象
在 kustomization 中ConfigMap 对象名称可能会通过 `namePrefix``nameSuffix``hashing` 来更改 CRD 对象中该 ConfigMap 对象的名称,
引用时需要以相同的方式使用 `namePrefix``nameSuffix``hashing` 来进行更新。
Annotations 可以放入 openAPI 的定义中:
- "x-kubernetes-annotation": ""
- "x-kubernetes-label-selector": ""
- "x-kubernetes-identity": ""
- "x-kubernetes-object-ref-api-version": "v1",
- "x-kubernetes-object-ref-kind": "Secret",
- "x-kubernetes-object-ref-name-key": "name",
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
crds:
- crds/typeA.yaml
- crds/typeB.yaml
```

View File

@@ -0,0 +1,26 @@
---
title: "generatorOptions"
linkTitle: "generatorOptions"
type: docs
description: >
控制生成 [ConfigMap](/kustomize/zh/api-reference/kustomization/configmapgenerator) 和 [Secret](/kustomize/zh/api-reference/kustomization/secretgenerator) 的行为。
---
此外,在每个生成器中,还可以按每个资源级别设置 generatorOptions具体使用方法请参见[configMapGenerator](/kustomize/zh/api-reference/kustomization/configmapgenerator)和[secretGenerator](/kustomize/zh/api-reference/kustomization/secretgenerator)。
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
generatorOptions:
# labels to add to all generated resources
labels:
kustomize.generated.resources: somevalue
# annotations to add to all generated resources
annotations:
kustomize.generated.resource: somevalue
# disableNameSuffixHash is true disables the default behavior of adding a
# suffix to the names of generated resources that is a hash of
# the resource contents.
disableNameSuffixHash: true
```

View File

@@ -0,0 +1,51 @@
---
title: "images"
linkTitle: "images"
type: docs
description: >
修改镜像的名称、tag 或 image digest。
---
修改镜像的名称、tag 或 image digest ,而无需使用 patches 。例如,对于这种 kubernetes Deployment 片段:
```yaml
kind: Deployment
...
spec:
template:
spec:
containers:
- name: mypostgresdb
image: postgres:8
- name: nginxapp
image: nginx:1.7.9
- name: myapp
image: my-demo-app:latest
- name: alpine-app
image: alpine:3.7
```
想要将 `image` 做如下更改:
-`postgres:8` 改为 `my-registry/my-postgres:v1`
- 将 nginx tag 从 `1.7.9` 改为 `1.8.0`
- 将镜像名称 `my-demo-app` 改为 `my-app`
- 将 alpine 的 tag `3.7` 改为 digest 值
只需在 *kustomization* 中添加以下内容:
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: postgres
newName: my-registry/my-postgres
newTag: v1
- name: nginx
newTag: 1.8.0
- name: my-demo-app
newName: my-app
- name: alpine
digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
```

View File

@@ -0,0 +1,16 @@
---
title: "namePrefix"
linkTitle: "namePrefix"
type: docs
description: >
为所有资源和引用的名称添加前缀。
---
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: alices-
```
deployment 名称从 `wordpress` 变为 `alices-wordpress`

View File

@@ -0,0 +1,16 @@
---
title: "namespace"
linkTitle: "namespace"
type: docs
description: >
为所有资源添加 namespace。
---
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: my-namespace
```
如果在资源上设置了现有 namespace则将覆盖现有 namespace如果在资源上未设置现有 namespace则使用现有 namespace。

View File

@@ -0,0 +1,18 @@
---
title: "nameSuffix"
linkTitle: "nameSuffix"
type: docs
description: >
为所有资源和引用的名称添加后缀。
---
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
nameSuffix: -v2
```
deployment 名称从 `wordpress` 变为 `wordpress-v2`
**注意:** 如果资源类型是 ConfigMap 或 Secret则在哈希值之前添加后缀。

View File

@@ -0,0 +1,47 @@
---
title: "patches"
linkTitle: "patches"
type: docs
description: >
Patch resources
---
[strategic merge]: /kustomize/zh/api-reference/glossary#patchstrategicmerge
[JSON]: /kustomize/zh/api-reference/glossary#patchjson6902
Patches 在资源上添加或覆盖字段Kustomization 使用 `patches` 字段来提供该功能。
`patches` 字段包含要按指定顺序应用的 patch 列表。
patch 可以:
- 是一个 [strategic merge] patch或者是一个 [JSON] patch。
- 也可以是 patch 文件或 inline string
- 针对单个资源或多个资源
目标选择器可以通过 group、version、kind、name、namespace、标签选择器和注释选择器来选择资源选择一个或多个匹配所有**指定**字段的资源来应用 patch。
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- path: patch.yaml
target:
group: apps
version: v1
kind: Deployment
name: deploy.*
labelSelector: "env=dev"
annotationSelector: "zone=west"
- patch: |-
- op: replace
path: /some/existing/path
value: new value
target:
kind: MyKind
labelSelector: "env=dev"
```
patch 目标选择器的 `name``namespace` 字段是自动锚定的正则表达式。这意味着 `myapp` 的值相当于 `^myapp$`

View File

@@ -0,0 +1,44 @@
---
title: "patchesStrategicMerge"
linkTitle: "patchesStrategicMerge"
type: docs
description: >
使用 strategic merge patch 标准 Patch resources.
---
此列表中的每个条目都应可以解析为 [StrategicMergePatch](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md).
这些(也可能是部分的)资源文件中的 name 必须与已经通过 `resources` 加载的 name 字段匹配,或者通过 `bases` 中的 name 字段匹配。这些条目将用于 _patch_(修改)已知资源。
推荐使用小的 patches例如修改内存的 request/limit更改 ConfigMap 中的 env 变量等。小的 patches 易于维护和查看,并且易于在 overlays 中混合使用。
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patchesStrategicMerge:
- service_port_8888.yaml
- deployment_increase_replicas.yaml
- deployment_increase_memory.yaml
```
patch 内容也可以是一个inline string
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patchesStrategicMerge:
- |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
template:
spec:
containers:
- name: nginx
image: nignx:latest
```
请注意kustomize 不支持同一个 patch 对象中包含多个 _删除_ 指令。要从一个对象中删除多个字段或切片元素,需要创建一个单独的 patch以执行所有需要的删除。

View File

@@ -0,0 +1,68 @@
---
title: "patchesJson6902"
linkTitle: "patchesJson6902"
type: docs
description: >
使用 [json 6902 标准](https://tools.ietf.org/html/rfc6902) Patch resources
---
patchesJson6902 列表中的每个条目都应可以解析为 kubernetes 对象和将应用于该对象的 [JSON patch](https://tools.ietf.org/html/rfc6902)。
目标字段指向的 kubernetes 对象的 group、 version、 kind、 name 和 namespace 在同一 kustomization 内 path 字段内容是 JSON patch 文件的相对路径。
patch 文件中的内容可以如下这种 JSON 格式:
```json
[
{"op": "add", "path": "/some/new/path", "value": "value"},
{"op": "replace", "path": "/some/existing/path", "value": "new value"}
]
```
使 YAML
```yaml
- op: add
path: /some/new/path
value: value
- op: replace
path: /some/existing/path
value: new value
```
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patchesJson6902:
- target:
version: v1
kind: Deployment
name: my-deployment
path: add_init_container.yaml
- target:
version: v1
kind: Service
name: my-service
path: add_service_annotation.yaml
```
patch 内容也可以是一个inline string
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patchesJson6902:
- target:
version: v1
kind: Deployment
name: my-deployment
patch: |-
- op: add
path: /some/new/path
value: value
- op: replace
path: /some/existing/path
value: "new value"
```

View File

@@ -0,0 +1,39 @@
---
title: "replicas"
linkTitle: "replicas"
type: docs
description: >
修改资源的副本数。
---
对于如下 kubernetes Deployment 片段:
```yaml
# deployment.yaml
kind: Deployment
metadata:
name: deployment-name
spec:
replicas: 3
```
在 kustomization 中添加以下内容,将副本数更改为 5
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
replicas:
- name: deployment-name
count: 5
```
该字段内容为列表,所以可以同时修改许多资源。
由于这个声明无法设置 `kind:``group:`,所以他只能匹配如下资源中的一种:
- `Deployment`
- `ReplicationController`
- `ReplicaSet`
- `StatefulSet`
对于更复杂的用例,请使用 patch 。

View File

@@ -0,0 +1,30 @@
---
title: "resources"
linkTitle: "resources"
type: docs
description: >
包含的资源。
---
该条目可以是指向本地目录的相对路径,也可以是指向远程仓库中的目录的 URL例如
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- myNamespace.yaml
- sub-dir/some-deployment.yaml
- ../../commonbase
- github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v1.0.6
- deployment.yaml
- github.com/kubernets-sigs/kustomize/examples/helloWorld?ref=test-branch
```
将以深度优先的顺序读取和处理资源。
文件应包含 YAML 格式的 k8s 资源。一个资源描述文件可以含有多个由(`---`)分隔的资源。
应该包含 `resources` 字段的 kustomization 文件的指定文件目录的相对路径。
[hashicorp URL]: https://github.com/hashicorp/go-getter#url-format
目录规范可以是相对、绝对或部分的 URL。URL 规范应遵循 [hashicorp URL] 格式。该目录必须包含 `kustomization.yaml` 文件。

View File

@@ -0,0 +1,44 @@
---
title: "secretGenerator"
linkTitle: "secretGenerator"
type: docs
description: >
生成 Secret 资源。
---
列表中的每个条目都将生成一个 Secret合计可以生成 n 个 Secrets
功能与之前描述的 [configMapGenerator](/kustomize/zh/api-reference/kustomization/configmapgenerator) 字段类似。
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
secretGenerator:
- name: app-tls
files:
- secret/tls.cert
- secret/tls.key
type: "kubernetes.io/tls"
- name: app-tls-namespaced
# you can define a namespace to generate
# a secret in, defaults to: "default"
namespace: apps
files:
- tls.crt=catsecret/tls.cert
- tls.key=secret/tls.key
type: "kubernetes.io/tls"
- name: env_file_secret
envs:
- env.txt
type: Opaque
- name: secret-with-annotation
files:
- app-config.yaml
type: Opaque
options:
annotations:
app_config: "true"
labels:
app.kubernetes.io/name: "app2"
```

View File

@@ -0,0 +1,65 @@
---
title: "vars"
linkTitle: "vars"
type: docs
description: >
Substitute name references.
---
Vars 用于从一个 resource 字段中获取值,并将该值插入指定位置 - 反射功能。
例如,假设需要在容器的 command 中指定了 Service 对象的名称,并在容器的 env 中指定了 Secret 对象的名称来确保以下内容可以正常工作:
```yaml
containers:
- image: myimage
command: ["start", "--host", "$(MY_SERVICE_NAME)"]
env:
- name: SECRET_TOKEN
value: $(SOME_SECRET_NAME)
```
则可以在 `vars` 中添加如下内容:
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
vars:
- name: SOME_SECRET_NAME
objref:
kind: Secret
name: my-secret
apiVersion: v1
- name: MY_SERVICE_NAME
objref:
kind: Service
name: my-service
apiVersion: v1
fieldref:
fieldpath: metadata.name
- name: ANOTHER_DEPLOYMENTS_POD_RESTART_POLICY
objref:
kind: Deployment
name: my-deployment
apiVersion: apps/v1
fieldref:
fieldpath: spec.template.spec.restartPolicy
```
var 是包含该对象的变量名、对象引用和字段引用的元组。
字段引用是可选的,默认为 `metadata.name`,这是正常的默认值,因为 kustomize 用于生成或修改 resources 的名称。
在撰写本文档时,仅支持字符串类型字段,不支持 intsboolsarrays 等。例如在某些pod模板的容器编号2中提取镜像的名称是不可能的。
变量引用,即字符串 '$(FOO)' ,只能放在 kustomize 配置指定的特定对象的特定字段中。
关于 vars 的默认配置数据可以查看:
[/api/konfig/builtinpluginconsts/varreference.go](/api/konfig/builtinpluginconsts/varreference.go)
默认目标是所有容器 command args 和 env 字段。
Vars _不应该_ 被用于 kustomize 已经处理过的配置中插入 names 。
例如, Deployment 可以通过 name 引用 ConfigMap ,如果 kustomize 更改 ConfigMap 的名称,则知道更改 Deployment 中的引用的 name 。