Skip to content

Commit 84e6163

Browse files
committed
[zh] sync /configuration/overview.md
1 parent 8929356 commit 84e6163

File tree

1 file changed

+95
-34
lines changed

1 file changed

+95
-34
lines changed

content/zh-cn/docs/concepts/configuration/overview.md

Lines changed: 95 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@ content_type: concept
44
weight: 10
55
---
66
<!--
7+
reviewers:
8+
- mikedanese
79
title: Configuration Best Practices
810
content_type: concept
911
weight: 10
1012
-->
1113

1214
<!-- overview -->
1315
<!--
14-
This document highlights and consolidates configuration best practices that are introduced throughout the user guide, Getting Started documentation, and examples.
16+
This document highlights and consolidates configuration best practices that are introduced
17+
throughout the user guide, Getting Started documentation, and examples.
1518
-->
1619
本文档重点介绍并整合了整个用户指南、入门文档和示例中介绍的配置最佳实践。
1720

1821
<!--
19-
This is a living document. If you think of something that is not on this list but might be useful to others, please don't hesitate to file an issue or submit a PR.
22+
This is a living document. If you think of something that is not on this list but might be useful
23+
to others, please don't hesitate to file an issue or submit a PR.
2024
-->
2125
这是一份不断改进的文件。
2226
如果你认为某些内容缺失但可能对其他人有用,请不要犹豫,提交 Issue 或提交 PR。
@@ -33,26 +37,33 @@ This is a living document. If you think of something that is not on this list bu
3337
- 定义配置时,请指定最新的稳定 API 版本。
3438

3539
<!--
36-
- Configuration files should be stored in version control before being pushed to the cluster. This allows you to quickly roll back a configuration change if necessary. It also aids cluster re-creation and restoration.
40+
- Configuration files should be stored in version control before being pushed to the cluster. This
41+
allows you to quickly roll back a configuration change if necessary. It also aids cluster
42+
re-creation and restoration.
3743
-->
3844
- 在推送到集群之前,配置文件应存储在版本控制中。
3945
这允许你在必要时快速回滚配置更改。
40-
它还有助于集群重新创建和恢复。
46+
它还有助于集群重新创建和恢复。
4147

4248
<!--
43-
- Write your configuration files using YAML rather than JSON. Though these formats can be used interchangeably in almost all scenarios, YAML tends to be more user-friendly.
49+
- Write your configuration files using YAML rather than JSON. Though these formats can be used
50+
interchangeably in almost all scenarios, YAML tends to be more user-friendly.
4451
-->
4552
- 使用 YAML 而不是 JSON 编写配置文件。虽然这些格式几乎可以在所有场景中互换使用,但 YAML 往往更加用户友好。
4653

4754
<!--
48-
- Group related objects into a single file whenever it makes sense. One file is often easier to manage than several. See the [guestbook-all-in-one.yaml](https://github.com/kubernetes/examples/tree/master/guestbook/all-in-one/guestbook-all-in-one.yaml) file as an example of this syntax.
55+
- Group related objects into a single file whenever it makes sense. One file is often easier to
56+
manage than several. See the
57+
[guestbook-all-in-one.yaml](https://github.com/kubernetes/examples/tree/master/guestbook/all-in-one/guestbook-all-in-one.yaml)
58+
file as an example of this syntax.
4959
-->
5060
- 只要有意义,就将相关对象分组到一个文件中。一个文件通常比几个文件更容易管理。
5161
请参阅 [guestbook-all-in-one.yaml](https://github.com/kubernetes/examples/tree/master/guestbook/all-in-one/guestbook-all-in-one.yaml)
5262
文件作为此语法的示例。
5363

5464
<!--
55-
- Note also that many `kubectl` commands can be called on a directory. For example, you can call `kubectl apply` on a directory of config files.
65+
- Note also that many `kubectl` commands can be called on a directory. For example, you can call
66+
`kubectl apply` on a directory of config files.
5667
-->
5768
- 另请注意,可以在目录上调用许多 `kubectl` 命令。
5869
例如,你可以在配置文件的目录中调用 `kubectl apply`
@@ -67,16 +78,22 @@ This is a living document. If you think of something that is not on this list bu
6778
-->
6879
- 将对象描述放在注释中,以便更好地进行内省。
6980

70-
7181
<!--
7282
## "Naked" Pods versus ReplicaSets, Deployments, and Jobs {#naked-pods-vs-replicasets-deployments-and-jobs}
7383
-->
74-
## “独立的“ Pod 与 ReplicaSet 、Deployment 和 Job {#naked-pods-vs-replicasets-deployments-and-jobs}
84+
## “独立的“ Pod 与 ReplicaSet、Deployment 和 Job {#naked-pods-vs-replicasets-deployments-and-jobs}
7585

7686
<!--
77-
- Don't use naked Pods (that is, Pods not bound to a [ReplicaSet](/docs/concepts/workloads/controllers/replicaset/) or [Deployment](/docs/concepts/workloads/controllers/deployment/)) if you can avoid it. Naked Pods will not be rescheduled in the event of a node failure.
78-
79-
A Deployment, which both creates a ReplicaSet to ensure that the desired number of Pods is always available, and specifies a strategy to replace Pods (such as [RollingUpdate](/docs/concepts/workloads/controllers/deployment/#rolling-update-deployment)), is almost always preferable to creating Pods directly, except for some explicit [`restartPolicy: Never`](/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy) scenarios. A [Job](/docs/concepts/workloads/controllers/jobs-run-to-completion/) may also be appropriate.
87+
- Don't use naked Pods (that is, Pods not bound to a [ReplicaSet](/docs/concepts/workloads/controllers/replicaset/) or
88+
[Deployment](/docs/concepts/workloads/controllers/deployment/)) if you can avoid it. Naked Pods
89+
will not be rescheduled in the event of a node failure.
90+
91+
A Deployment, which both creates a ReplicaSet to ensure that the desired number of Pods is
92+
always available, and specifies a strategy to replace Pods (such as
93+
[RollingUpdate](/docs/concepts/workloads/controllers/deployment/#rolling-update-deployment)), is
94+
almost always preferable to creating Pods directly, except for some explicit
95+
[`restartPolicy: Never`](/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy) scenarios.
96+
A [Job](/docs/concepts/workloads/controllers/job/) may also be appropriate.
8097
-->
8198
- 如果可能,不要使用独立的 Pod(即,未绑定到
8299
[ReplicaSet](/zh-cn/docs/concepts/workloads/controllers/replicaset/)
@@ -95,9 +112,11 @@ This is a living document. If you think of something that is not on this list bu
95112
## 服务 {#services}
96113

97114
<!--
98-
- Create a [Service](/docs/concepts/services-networking/service/) before its corresponding backend workloads (Deployments or ReplicaSets), and before any workloads that need to access it. When Kubernetes starts a container, it provides environment variables pointing to all the Services which were running when the container was started. For example, if a Service named `foo` exists, all containers will get the following variables in their initial environment:
99-
100-
*This does imply an ordering requirement* - any `Service` that a `Pod` wants to access must be created before the `Pod` itself, or else the environment variables will not be populated. DNS does not have this restriction.
115+
- Create a [Service](/docs/concepts/services-networking/service/) before its corresponding backend
116+
workloads (Deployments or ReplicaSets), and before any workloads that need to access it.
117+
When Kubernetes starts a container, it provides environment variables pointing to all the Services
118+
which were running when the container was started. For example, if a Service named `foo` exists,
119+
all containers will get the following variables in their initial environment:
101120
-->
102121
- 在创建相应的后端工作负载(Deployment 或 ReplicaSet),以及在需要访问它的任何工作负载之前创建
103122
[服务](/zh-cn/docs/concepts/services-networking/service/)
@@ -109,22 +128,38 @@ This is a living document. If you think of something that is not on this list bu
109128
FOO_SERVICE_PORT=<the port the Service is running on>
110129
```
111130

131+
<!--
132+
*This does imply an ordering requirement* - any `Service` that a `Pod` wants to access must be
133+
created before the `Pod` itself, or else the environment variables will not be populated.
134+
DNS does not have this restriction.
135+
-->
112136
**这确实意味着在顺序上的要求** - 必须在 `Pod` 本身被创建之前创建 `Pod` 想要访问的任何 `Service`
113137
否则将环境变量不会生效。DNS 没有此限制。
114138

115139
<!--
116-
- An optional (though strongly recommended) [cluster add-on](/docs/concepts/cluster-administration/addons/) is a DNS server. The
117-
DNS server watches the Kubernetes API for new `Services` and creates a set of DNS records for each. If DNS has been enabled throughout the cluster then all `Pods` should be able to do name resolution of `Services` automatically.
140+
- An optional (though strongly recommended) [cluster add-on](/docs/concepts/cluster-administration/addons/)
141+
is a DNS server. The DNS server watches the Kubernetes API for new `Services` and creates a set
142+
of DNS records for each. If DNS has been enabled throughout the cluster then all `Pods` should be
143+
able to do name resolution of `Services` automatically.
118144
-->
119145
- 一个可选(尽管强烈推荐)的[集群插件](/zh-cn/docs/concepts/cluster-administration/addons/)
120146
是 DNS 服务器。DNS 服务器为新的 `Services` 监视 Kubernetes API,并为每个创建一组 DNS 记录。
121147
如果在整个集群中启用了 DNS,则所有 `Pod` 应该能够自动对 `Services` 进行名称解析。
122148

123149
<!--
124-
- Don't specify a `hostPort` for a Pod unless it is absolutely necessary. When you bind a Pod to a `hostPort`, it limits the number of places the Pod can be scheduled, because each <`hostIP`, `hostPort`, `protocol`> combination must be unique. If you don't specify the `hostIP` and `protocol` explicitly, Kubernetes will use `0.0.0.0` as the default `hostIP` and `TCP` as the default `protocol`.
125-
126-
If you only need access to the port for debugging purposes, you can use the [apiserver proxy](/docs/tasks/access-application-cluster/access-cluster/#manually-constructing-apiserver-proxy-urls) or [`kubectl port-forward`](/docs/tasks/access-application-cluster/port-forward-access-application-cluster/).
127-
If you explicitly need to expose a Pod's port on the node, consider using a [NodePort](/docs/concepts/services-networking/service/#type-nodeport) Service before resorting to `hostPort`.
150+
- Don't specify a `hostPort` for a Pod unless it is absolutely necessary. When you bind a Pod to a
151+
`hostPort`, it limits the number of places the Pod can be scheduled, because each <`hostIP`,
152+
`hostPort`, `protocol`> combination must be unique. If you don't specify the `hostIP` and
153+
`protocol` explicitly, Kubernetes will use `0.0.0.0` as the default `hostIP` and `TCP` as the
154+
default `protocol`.
155+
156+
If you only need access to the port for debugging purposes, you can use the
157+
[apiserver proxy](/docs/tasks/access-application-cluster/access-cluster/#manually-constructing-apiserver-proxy-urls)
158+
or [`kubectl port-forward`](/docs/tasks/access-application-cluster/port-forward-access-application-cluster/).
159+
160+
If you explicitly need to expose a Pod's port on the node, consider using a
161+
[NodePort](/docs/concepts/services-networking/service/#type-nodeport) Service before resorting to
162+
`hostPort`.
128163
-->
129164
- 不要为 Pod 指定 `hostPort`,除非非常有必要这样做。
130165
当你为 Pod 绑定了 `hostPort`,那么能够运行该 Pod 的节点就有限了,因为每个 `<hostIP, hostPort, protocol>` 组合必须是唯一的。
@@ -145,8 +180,9 @@ DNS server watches the Kubernetes API for new `Services` and creates a set of DN
145180
- 避免使用 `hostNetwork`,原因与 `hostPort` 相同。
146181

147182
<!--
148-
- Use [headless Services](/docs/concepts/services-networking/service/#headless-
149-
services) (which have a `ClusterIP` of `None`) for service discovery when you don't need `kube-proxy` load balancing.
183+
- Use [headless Services](/docs/concepts/services-networking/service/#headless-services)
184+
(which have a `ClusterIP` of `None`) for service discovery when you don't need `kube-proxy`
185+
load balancing.
150186
-->
151187
- 当你不需要 `kube-proxy` 负载均衡时,
152188
使用[无头服务](/zh-cn/docs/concepts/services-networking/service/#headless-services)
@@ -158,9 +194,21 @@ services) (which have a `ClusterIP` of `None`) for service discovery when you do
158194
## 使用标签 {#using-labels}
159195

160196
<!--
161-
- Define and use [labels](/docs/concepts/overview/working-with-objects/labels/) that identify __semantic attributes__ of your application or Deployment, such as `{ app.kubernetes.io/name: MyApp, tier: frontend, phase: test, deployment: v3 }`. You can use these labels to select the appropriate Pods for other resources; for example, a Service that selects all `tier: frontend` Pods, or all `phase: test` components of `app.kubernetes.io/name: MyApp`. See the [guestbook](https://github.com/kubernetes/examples/tree/master/guestbook/) app for examples of this approach.
162-
A Service can be made to span multiple Deployments by omitting release-specific labels from its selector. When you need to update a running service without downtime, use a [Deployment](/docs/concepts/workloads/controllers/deployment/).
163-
A desired state of an object is described by a Deployment, and if changes to that spec are _applied_, the deployment controller changes the actual state to the desired state at a controlled rate.
197+
- Define and use [labels](/docs/concepts/overview/working-with-objects/labels/) that identify
198+
__semantic attributes__ of your application or Deployment, such as `{ app.kubernetes.io/name:
199+
MyApp, tier: frontend, phase: test, deployment: v3 }`. You can use these labels to select the
200+
appropriate Pods for other resources; for example, a Service that selects all `tier: frontend`
201+
Pods, or all `phase: test` components of `app.kubernetes.io/name: MyApp`.
202+
See the [guestbook](https://github.com/kubernetes/examples/tree/master/guestbook/) app
203+
for examples of this approach.
204+
205+
A Service can be made to span multiple Deployments by omitting release-specific labels from its
206+
selector. When you need to update a running service without downtime, use a
207+
[Deployment](/docs/concepts/workloads/controllers/deployment/).
208+
209+
A desired state of an object is described by a Deployment, and if changes to that spec are
210+
_applied_, the deployment controller changes the actual state to the desired state at a controlled
211+
rate.
164212
-->
165213
- 定义并使用[标签](/zh-cn/docs/concepts/overview/working-with-objects/labels/)来识别应用程序
166214
或 Deployment 的 **语义属性**,例如 `{ app.kubernetes.io/name: MyApp, tier: frontend, phase: test, deployment: v3 }`
@@ -175,16 +223,23 @@ A desired state of an object is described by a Deployment, and if changes to tha
175223
控制器以受控速率将实际状态改变为期望状态。
176224

177225
<!--
178-
- Use the [Kubernetes common labels](/docs/concepts/overview/working-with-objects/common-labels/) for common use cases. These standardized labels enrich the metadata in a way that allows tools, including `kubectl` and [dashboard](/docs/tasks/access-application-cluster/web-ui-dashboard), to work in an interoperable way.
226+
- Use the [Kubernetes common labels](/docs/concepts/overview/working-with-objects/common-labels/)
227+
for common use cases. These standardized labels enrich the metadata in a way that allows tools,
228+
including `kubectl` and [dashboard](/docs/tasks/access-application-cluster/web-ui-dashboard), to
229+
work in an interoperable way.
179230
-->
180-
181231
- 对于常见场景,应使用 [Kubernetes 通用标签](/zh-cn/docs/concepts/overview/working-with-objects/common-labels/)
182232
这些标准化的标签丰富了对象的元数据,使得包括 `kubectl`
183233
[仪表板(Dashboard)](/zh-cn/docs/tasks/access-application-cluster/web-ui-dashboard)
184234
这些工具能够以可互操作的方式工作。
185235

186236
<!--
187-
- You can manipulate labels for debugging. Because Kubernetes controllers (such as ReplicaSet) and Services match to Pods using selector labels, removing the relevant labels from a Pod will stop it from being considered by a controller or from being served traffic by a Service. If you remove the labels of an existing Pod, its controller will create a new Pod to take its place. This is a useful way to debug a previously "live" Pod in a "quarantine" environment. To interactively remove or add labels, use [`kubectl label`](/docs/reference/generated/kubectl/kubectl-commands#label).
237+
- You can manipulate labels for debugging. Because Kubernetes controllers (such as ReplicaSet) and
238+
Services match to Pods using selector labels, removing the relevant labels from a Pod will stop
239+
it from being considered by a controller or from being served traffic by a Service. If you remove
240+
the labels of an existing Pod, its controller will create a new Pod to take its place. This is a
241+
useful way to debug a previously "live" Pod in a "quarantine" environment. To interactively remove
242+
or add labels, use [`kubectl label`](/docs/reference/generated/kubectl/kubectl-commands#label).
188243
-->
189244
- 你可以操纵标签进行调试。
190245
由于 Kubernetes 控制器(例如 ReplicaSet)和服务使用选择器标签来匹配 Pod,
@@ -199,20 +254,26 @@ A desired state of an object is described by a Deployment, and if changes to tha
199254
## 使用 kubectl {#using-kubectl}
200255

201256
<!--
202-
- Use `kubectl apply -f <directory>`. This looks for Kubernetes configuration in all `.yaml`, `.yml`, and `.json` files in `<directory>` and passes it to `apply`.
257+
- Use `kubectl apply -f <directory>`. This looks for Kubernetes configuration in all `.yaml`,
258+
`.yml`, and `.json` files in `<directory>` and passes it to `apply`.
203259
-->
204-
- 使用 `kubectl apply -f <directory>`
205-
它在 `<directory>` 中的所有` .yaml``.yml``.json` 文件中查找 Kubernetes 配置,并将其传递给 `apply`
260+
- 使用 `kubectl apply -f <目录>`
261+
它在 `<目录>` 中的所有 `.yaml``.yml``.json` 文件中查找 Kubernetes 配置,并将其传递给 `apply`
206262

207263
<!--
208-
- Use label selectors for `get` and `delete` operations instead of specific object names. See the sections on [label selectors](/docs/concepts/overview/working-with-objects/labels/#label-selectors) and [using labels effectively](/docs/concepts/cluster-administration/manage-deployment/#using-labels-effectively).
264+
- Use label selectors for `get` and `delete` operations instead of specific object names. See the
265+
sections on [label selectors](/docs/concepts/overview/working-with-objects/labels/#label-selectors)
266+
and [using labels effectively](/docs/concepts/cluster-administration/manage-deployment/#using-labels-effectively).
209267
-->
210268
- 使用标签选择器进行 `get``delete` 操作,而不是特定的对象名称。
211269
- 请参阅[标签选择器](/zh-cn/docs/concepts/overview/working-with-objects/labels/#label-selectors)
212270
[有效使用标签](/zh-cn/docs/concepts/cluster-administration/manage-deployment/#using-labels-effectively)部分。
213271

214272
<!--
215-
- Use `kubectl create deployment` and `kubectl expose` to quickly create single-container Deployments and Services. See [Use a Service to Access an Application in a Cluster](/docs/tasks/access-application-cluster/service-access-application-cluster/) for an example.
273+
- Use `kubectl create deployment` and `kubectl expose` to quickly create single-container
274+
Deployments and Services.
275+
See [Use a Service to Access an Application in a Cluster](/docs/tasks/access-application-cluster/service-access-application-cluster/)
276+
for an example.
216277
-->
217278
- 使用 `kubectl create deployment``kubectl expose` 来快速创建单容器 Deployment 和 Service。
218279
有关示例,请参阅[使用服务访问集群中的应用程序](/zh-cn/docs/tasks/access-application-cluster/service-access-application-cluster/)

0 commit comments

Comments
 (0)