Skip to content

Commit c60f5f2

Browse files
authored
Merge pull request #46374 from my-git9/pt-9037
[zh-cn] sync basic-stateful-set.md
2 parents 77713d0 + 57f8e10 commit c60f5f2

File tree

1 file changed

+128
-68
lines changed

1 file changed

+128
-68
lines changed

content/zh-cn/docs/tutorials/stateful-application/basic-stateful-set.md

Lines changed: 128 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ After this tutorial, you will be familiar with the following.
123123
## 创建 StatefulSet {#creating-a-statefulset}
124124

125125
<!--
126-
Begin by creating a StatefulSet using the example below. It is similar to the
127-
example presented in the
126+
Begin by creating a StatefulSet (and the Service that it relies upon) using
127+
the example below. It is similar to the example presented in the
128128
[StatefulSets](/docs/concepts/workloads/controllers/statefulset/) concept.
129129
It creates a [headless Service](/docs/concepts/services-networking/service/#headless-services),
130130
`nginx`, to publish the IP addresses of Pods in the StatefulSet, `web`.
131131
-->
132-
作为开始,使用如下示例创建一个 StatefulSet。它和
132+
作为开始,使用如下示例创建一个 StatefulSet(以及它所依赖的 Service)。它和
133133
[StatefulSet](/zh-cn/docs/concepts/workloads/controllers/statefulset/) 概念中的示例相似。
134134
它创建了一个 [Headless Service](/zh-cn/docs/concepts/services-networking/service/#headless-services)
135135
`nginx` 用来发布 StatefulSet `web` 中的 Pod 的 IP 地址。
@@ -204,6 +204,11 @@ web 2 1 20s
204204
-->
205205
### 顺序创建 Pod {#ordered-pod-creation}
206206

207+
<!--
208+
A StatefulSet defaults to creating its Pods in a strict order.
209+
-->
210+
StatefulSet 默认以严格的顺序创建其 Pod。
211+
207212
<!--
208213
For a StatefulSet with _n_ replicas, when Pods are being deployed, they are
209214
created sequentially, ordered from _{0..n-1}_. Examine the output of the
@@ -238,12 +243,16 @@ web-1 1/1 Running 0 18s
238243
Notice that the `web-1` Pod is not launched until the `web-0` Pod is
239244
_Running_ (see [Pod Phase](/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase))
240245
and _Ready_ (see `type` in [Pod Conditions](/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions)).
246+
247+
Later in this tutorial you will practice [parallel startup](#parallel-pod-management).
241248
-->
242249
请注意,直到 `web-0` Pod 处于 **Running**(请参阅
243250
[Pod 阶段](/zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase)
244251
**Ready**(请参阅 [Pod 状况](/zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions)中的
245252
`type`)状态后,`web-1` Pod 才会被启动。
246253

254+
在本教程的后面部分,你将练习[并行启动](#parallel-pod-management)
255+
247256
{{< note >}}
248257
<!--
249258
To configure the integer ordinal assigned to each Pod in a StatefulSet, see
@@ -497,11 +506,13 @@ Address 1: 10.244.2.8
497506
The Pods' ordinals, hostnames, SRV records, and A record names have not changed,
498507
but the IP addresses associated with the Pods may have changed. In the cluster
499508
used for this tutorial, they have. This is why it is important not to configure
500-
other applications to connect to Pods in a StatefulSet by IP address.
509+
other applications to connect to Pods in a StatefulSet by the IP address
510+
of a particular Pod (it is OK to connect to Pods by resolving their hostname).
501511
-->
502512
Pod 的序号、主机名、SRV 条目和记录名称没有改变,但和 Pod 相关联的 IP 地址可能发生了改变。
503513
在本教程中使用的集群中它们就改变了。这就是为什么不要在其他应用中使用
504-
StatefulSet 中 Pod 的 IP 地址进行连接,这点很重要。
514+
StatefulSet 中特定 Pod 的 IP 地址进行连接,这点很重要
515+
(可以通过解析 Pod 的主机名来连接到 Pod)。
505516

506517
<!--
507518
#### Discovery for specific Pods in a StatefulSet
@@ -531,6 +542,20 @@ to Running and Ready.
531542
`web-1.nginx.default.svc.cluster.local`)。因为它们是稳定的,并且当你的
532543
Pod 的状态变为 Running 和 Ready 时,你的应用就能够发现它们的地址。
533544

545+
<!--
546+
If your application wants to find any healthy Pod in a StatefulSet,
547+
and therefore does not need to track each specific Pod,
548+
you could also connect to the IP address of a `type: ClusterIP` Service,
549+
backed by the Pods in that StatefulSet. You can use the same Service that
550+
tracks the StatefulSet (specified in the `serviceName` of the StatefulSet)
551+
or a separate Service that selects the right set of Pods.
552+
-->
553+
如果你的应用程序想要在 StatefulSet 中找到任一健康的 Pod,
554+
且不需要跟踪每个特定的 Pod,你还可以连接到由该 StatefulSet 中的 Pod 关联的
555+
`type: ClusterIP` Service 的 IP 地址。
556+
你可以使用跟踪 StatefulSet 的同一 Service
557+
(StatefulSet 中 `serviceName` 所指定的)或选择正确的 Pod 集的单独 Service。
558+
534559
<!--
535560
### Writing to stable Storage
536561
-->
@@ -701,12 +726,13 @@ PersistentVolumeClaim 相关联的 PersistentVolume 卷被重新挂载到了各
701726
## 扩容/缩容 StatefulSet {#scaling-a-statefulset}
702727

703728
<!--
704-
Scaling a StatefulSet refers to increasing or decreasing the number of replicas.
729+
Scaling a StatefulSet refers to increasing or decreasing the number of replicas
730+
(horizontal scaling).
705731
This is accomplished by updating the `replicas` field. You can use either
706732
[`kubectl scale`](/docs/reference/generated/kubectl/kubectl-commands/#scale) or
707733
[`kubectl patch`](/docs/reference/generated/kubectl/kubectl-commands/#patch) to scale a StatefulSet.
708734
-->
709-
扩容/缩容 StatefulSet 指增加或减少它的副本数。这通过更新 `replicas` 字段完成。
735+
扩容/缩容 StatefulSet 指增加或减少它的副本数。这通过更新 `replicas` 字段完成(水平缩放)
710736
你可以使用 [`kubectl scale`](/docs/reference/generated/kubectl/kubectl-commands/#scale)
711737
或者 [`kubectl patch`](/docs/reference/generated/kubectl/kubectl-commands/#patch) 来扩容/缩容一个 StatefulSet。
712738

@@ -715,6 +741,14 @@ This is accomplished by updating the `replicas` field. You can use either
715741
-->
716742
### 扩容 {#scaling-up}
717743

744+
<!--
745+
Scaling up means adding more replicas.
746+
Provided that your app is able to distribute work across the StatefulSet, the new
747+
larger set of Pods can perform more of that work.
748+
-->
749+
扩容意味着添加更多副本。
750+
如果你的应用程序能够在整个 StatefulSet 范围内分派工作,则新的更大的 Pod 集可以执行更多的工作。
751+
718752
<!--
719753
In one terminal window, watch the Pods in the StatefulSet:
720754
-->
@@ -793,6 +827,14 @@ Pod,并且会等待前一个 Pod 变为 Running 和 Ready 才会启动下一
793827
-->
794828
### 缩容 {#scaling-down}
795829

830+
<!--
831+
Scaling down means reducing the number of replicas. For example, you
832+
might do this because the level of traffic to a service has decreased,
833+
and at the current scale there are idle resources.
834+
-->
835+
缩容意味着减少副本数量。
836+
例如,你可能因为服务的流量水平已降低并且在当前规模下存在空闲资源的原因执行缩容操作。
837+
796838
<!--
797839
In one terminal, watch the StatefulSet's Pods:
798840
-->
@@ -854,9 +896,9 @@ web-3 1/1 Terminating 0 42s
854896
### 顺序终止 Pod {#ordered-pod-termination}
855897

856898
<!--
857-
The controller deleted one Pod at a time, in reverse order with respect to its
858-
ordinal index, and it waited for each to be completely shutdown before
859-
deleting the next.
899+
The controller plane deleted one Pod at a time, in reverse order with respect
900+
to its ordinal index, and it waited for each Pod to be completely shut down
901+
before deleting the next one.
860902
-->
861903
控制器会按照与 Pod 序号索引相反的顺序每次删除一个 Pod。在删除下一个 Pod 前会等待上一个被完全关闭。
862904

@@ -879,12 +921,13 @@ www-web-4 Bound pvc-e11bb5f8-b508-11e6-932f-42010a800002 1Gi RWO
879921

880922
<!--
881923
There are still five PersistentVolumeClaims and five PersistentVolumes.
882-
When exploring a Pod's [stable storage](#writing-to-stable-storage), we saw that the PersistentVolumes
883-
mounted to the Pods of a StatefulSet are not deleted when the StatefulSet's Pods are deleted.
884-
This is still true when Pod deletion is caused by scaling the StatefulSet down.
924+
When exploring a Pod's [stable storage](#writing-to-stable-storage), you saw that
925+
the PersistentVolumes mounted to the Pods of a StatefulSet are not deleted when the
926+
StatefulSet's Pods are deleted. This is still true when Pod deletion is caused by
927+
scaling the StatefulSet down.
885928
-->
886929
五个 PersistentVolumeClaims 和五个 PersistentVolume 卷仍然存在。
887-
查看 Pod 的[稳定存储](#stable-storage)我们发现当删除 StatefulSet 的
930+
查看 Pod 的[稳定存储](#stable-storage)你会发现当删除 StatefulSet 的
888931
Pod 时,挂载到 StatefulSet 的 Pod 的 PersistentVolume 卷不会被删除。
889932
当这种删除行为是由 StatefulSet 缩容引起时也是一样的。
890933

@@ -1802,13 +1845,12 @@ identity.
18021845
这些系统仅仅要求唯一性和身份标志。
18031846

18041847
<!--
1805-
You can specify a Pod management policy to avoid this strict ordering;
1806-
either [`OrderedReady`](/docs/concepts/workloads/controllers/statefulset/#orderedready-pod-management) (the default)
1807-
or [`Parallel`](/docs/concepts/workloads/controllers/statefulset/#parallel-pod-management).
1848+
You can specify a [Pod management policy](/docs/concepts/workloads/controllers/statefulset/#pod-management-policies)
1849+
to avoid this strict ordering; either `OrderedReady` (the default), or `Parallel`.
18081850
-->
1809-
你可以指定 Pod 管理策略以避免这个严格的顺序;
1810-
你可以选择 [`OrderedReady`](/zh-cn/docs/concepts/workloads/controllers/statefulset/#orderedready-pod-management)(默认)或
1811-
[`Parallel`](/zh-cn/docs/concepts/workloads/controllers/statefulset/#parallel-pod-management)
1851+
你可以指定 [Pod 管理策略](/zh-cn/docs/concepts/workloads/controllers/statefulset/#pod-management-policies)
1852+
以避免这个严格的顺序;
1853+
你可以选择 `OrderedReady`(默认)或 `Parallel`
18121854

18131855
<!--
18141856
### OrderedReady Pod management
@@ -1823,20 +1865,51 @@ above.
18231865
`OrderedReady` Pod 管理策略是 StatefulSet 的默认选项。它告诉
18241866
StatefulSet 控制器遵循上文展示的顺序性保证。
18251867

1868+
<!--
1869+
Use this when your application requires or expects that changes, such as rolling out a new
1870+
version of your application, happen in the strict order of the ordinal (pod number) that the StatefulSet provides.
1871+
In other words, if you have Pods `app-0`, `app-1` and `app-2`, Kubernetes will update `app-0` first and check it.
1872+
Once the checks are good, Kubernetes updates `app-1` and finally `app-2`.
1873+
-->
1874+
当你的应用程序需要或期望变更(例如推出应用程序的新版本)按照 StatefulSet
1875+
提供的序号(Pod 编号)的严格顺序发生时,请使用此选项。
1876+
换句话说,如果你已经有了 Pod `app-0``app-1``app-2`,Kubernetes 将首先更新 `app-0` 并检查它。
1877+
一旦检查良好,Kubernetes 就会更新 `app-1`,最后更新 `app-2`
1878+
1879+
<!--
1880+
If you added two more Pods, Kubernetes would set up `app-3` and wait for that to become healthy before deploying
1881+
`app-4`.
1882+
1883+
Because this is the default setting, you've already practised using it.
1884+
-->
1885+
如果你再添加两个 Pod,Kubernetes 将设置 `app-3` 并等待其正常运行,然后再部署 `app-4`
1886+
1887+
因为这是默认设置,所以你已经在练习使用它,本教程不会让你再次执行类似的步骤。
1888+
18261889
<!--
18271890
### Parallel Pod management
18281891
-->
18291892
### Parallel Pod 管理策略 {#parallel-pod-management}
18301893

18311894
<!--
1832-
`Parallel` pod management tells the StatefulSet controller to launch or
1833-
terminate all Pods in parallel, and not to wait for Pods to become Running
1834-
and Ready or completely terminated prior to launching or terminating another
1835-
Pod. This option only affects the behavior for scaling operations. Updates are not affected.
1895+
The alternative, `Parallel` pod management tells the StatefulSet controller to launch or
1896+
terminate all Pods in parallel, and not to wait for Pods to become `Running`
1897+
and `Ready` or completely terminated prior to launching or terminating another
1898+
Pod.
18361899
-->
1837-
`Parallel` Pod 管理策略告诉 StatefulSet 控制器并行的终止所有 Pod,
1900+
另一种选择,`Parallel` Pod 管理策略告诉 StatefulSet 控制器并行的终止所有 Pod,
18381901
在启动或终止另一个 Pod 前,不必等待这些 Pod 变成 Running 和 Ready 或者完全终止状态。
18391902

1903+
<!--
1904+
The `Parallel` pod management option only affects the behavior for scaling operations. Updates are not affected;
1905+
Kubernetes still rolls out changes in order. For this tutorial, the application is very simple: a webserver that
1906+
tells you its hostname (because this is a StatefulSet, the hostname for each Pod is different and predictable).
1907+
-->
1908+
`Parallel` Pod 管理选项仅影响扩缩容操作的行为。
1909+
变更操作不受其影响;Kubernetes 仍然按顺序推出变更。
1910+
对于本教程,应用本身非常简单:它是一个告诉你其主机名的网络服务器(因为这是一个
1911+
StatefulSet,每个 Pod 的主机名都是不同的且可预测的)。
1912+
18401913
{{% code_sample file="application/web/web-parallel.yaml" %}}
18411914

18421915
<!--
@@ -1860,80 +1933,67 @@ kubectl get pod -l app=nginx --watch
18601933
```
18611934

18621935
<!--
1863-
In another terminal, create the StatefulSet and Service in the manifest:
1936+
In another terminal, reconfigure the StatefulSet for `Parallel` Pod management:
18641937
-->
1865-
在另一个终端窗口创建清单中的 StatefulSet 和 Service
1938+
在另一个终端中,重新配置 StatefulSet 以进行 `Parallel` Pod 管理
18661939

18671940
```shell
18681941
kubectl apply -f https://k8s.io/examples/application/web/web-parallel.yaml
18691942
```
18701943
```
1871-
service/nginx created
1872-
statefulset.apps/web created
1873-
```
1874-
1875-
<!--
1876-
Examine the output of the `kubectl get` command that you executed in the first terminal.
1877-
-->
1878-
查看你在第一个终端中运行的 `kubectl get` 命令的输出。
1879-
1880-
<!--
1881-
# This should already be running
1882-
-->
1883-
```shell
1884-
# 这应该已经处于 Running 状态
1885-
kubectl get pod -l app=nginx --watch
1886-
```
1887-
```
1888-
NAME READY STATUS RESTARTS AGE
1889-
web-0 0/1 Pending 0 0s
1890-
web-0 0/1 Pending 0 0s
1891-
web-1 0/1 Pending 0 0s
1892-
web-1 0/1 Pending 0 0s
1893-
web-0 0/1 ContainerCreating 0 0s
1894-
web-1 0/1 ContainerCreating 0 0s
1895-
web-0 1/1 Running 0 10s
1896-
web-1 1/1 Running 0 10s
1944+
service/nginx updated
1945+
statefulset.apps/web updated
18971946
```
18981947

18991948
<!--
1900-
The StatefulSet controller launched both `web-0` and `web-1` at almost the
1901-
same time.
1902-
-->
1903-
StatefulSet 控制器几乎同时启动了 `web-0``web-1`
1904-
1905-
<!--
1906-
Keep the second terminal open, and, in another terminal window scale the
1949+
Keep the terminal open where you're running the watch. In another terminal window, scale the
19071950
StatefulSet:
19081951
-->
1909-
保持第二个终端打开,并在另一个终端窗口中扩容 StatefulSet:
1952+
保持你运行监视进程的终端为打开状态,并在另一个终端窗口中扩容 StatefulSet:
19101953

19111954
```shell
1912-
kubectl scale statefulset/web --replicas=4
1955+
kubectl scale statefulset/web --replicas=5
19131956
```
19141957
```
19151958
statefulset.apps/web scaled
19161959
```
19171960

19181961
<!--
1919-
Examine the output of the terminal where the `kubectl get` command is running.
1962+
Examine the output of the terminal where the `kubectl get` command is running. It may look something like
19201963
-->
1921-
`kubectl get` 命令运行的终端里检查它的输出。
1964+
`kubectl get` 命令运行的终端里检查它的输出。它可能看起来像:
19221965

19231966
```
19241967
web-3 0/1 Pending 0 0s
19251968
web-3 0/1 Pending 0 0s
19261969
web-3 0/1 Pending 0 7s
19271970
web-3 0/1 ContainerCreating 0 7s
1928-
web-2 1/1 Running 0 10s
1971+
web-2 0/1 Pending 0 0s
1972+
web-4 0/1 Pending 0 0s
1973+
web-2 1/1 Running 0 8s
1974+
web-4 0/1 ContainerCreating 0 4s
19291975
web-3 1/1 Running 0 26s
1976+
web-4 1/1 Running 0 2s
19301977
```
19311978

19321979
<!--
1933-
The StatefulSet launched two new Pods, and it did not wait for
1934-
the first to become Running and Ready prior to launching the second.
1980+
The StatefulSet launched three new Pods, and it did not wait for
1981+
the first to become Running and Ready prior to launching the second and third Pods.
1982+
-->
1983+
StatefulSet 启动了三个新的 Pod,而且在启动第二和第三个之前并没有等待第一个变成 Running 和 Ready 状态。
1984+
1985+
<!--
1986+
This approach is useful if your workload has a stateful element, or needs Pods to be able to identify each other
1987+
with predictable naming, and especially if you sometimes need to provide a lot more capacity quickly. If this
1988+
simple web service for the tutorial suddenly got an extra 1,000,000 requests per minute then you would want to run
1989+
some more Pods - but you also would not want to wait for each new Pod to launch. Starting the extra Pods in parallel
1990+
cuts the time between requesting the extra capacity and having it available for use.
19351991
-->
1936-
StatefulSet 启动了两个新的 Pod,而且在启动第二个之前并没有等待第一个变成 Running 和 Ready 状态。
1992+
如果你的工作负载具有有状态元素,或者需要 Pod 能够通过可预测的命名来相互识别,
1993+
特别是当你有时需要快速提供更多容量时,此方法非常有用。
1994+
如果本教程的这个简单 Web 服务突然每分钟收到额外 1,000,000 个请求,
1995+
那么你可能会想要运行更多 Pod,但你也不想等待每个新 Pod 启动。
1996+
并行启动额外的 Pod 可以缩短请求额外容量和使其可供使用之间的时间。
19371997

19381998
## {{% heading "cleanup" %}}
19391999

0 commit comments

Comments
 (0)