@@ -123,13 +123,13 @@ After this tutorial, you will be familiar with the following.
123
123
## 创建 StatefulSet {#creating-a-statefulset}
124
124
125
125
<!--
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
128
128
[StatefulSets](/docs/concepts/workloads/controllers/statefulset/) concept.
129
129
It creates a [headless Service](/docs/concepts/services-networking/service/#headless-services),
130
130
`nginx`, to publish the IP addresses of Pods in the StatefulSet, `web`.
131
131
-->
132
- 作为开始,使用如下示例创建一个 StatefulSet。它和
132
+ 作为开始,使用如下示例创建一个 StatefulSet(以及它所依赖的 Service) 。它和
133
133
[ StatefulSet] ( /zh-cn/docs/concepts/workloads/controllers/statefulset/ ) 概念中的示例相似。
134
134
它创建了一个 [ Headless Service] ( /zh-cn/docs/concepts/services-networking/service/#headless-services )
135
135
` nginx ` 用来发布 StatefulSet ` web ` 中的 Pod 的 IP 地址。
@@ -204,6 +204,11 @@ web 2 1 20s
204
204
-->
205
205
### 顺序创建 Pod {#ordered-pod-creation}
206
206
207
+ <!--
208
+ A StatefulSet defaults to creating its Pods in a strict order.
209
+ -->
210
+ StatefulSet 默认以严格的顺序创建其 Pod。
211
+
207
212
<!--
208
213
For a StatefulSet with _n_ replicas, when Pods are being deployed, they are
209
214
created sequentially, ordered from _{0..n-1}_. Examine the output of the
@@ -238,12 +243,16 @@ web-1 1/1 Running 0 18s
238
243
Notice that the `web-1` Pod is not launched until the `web-0` Pod is
239
244
_Running_ (see [Pod Phase](/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase))
240
245
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).
241
248
-->
242
249
请注意,直到 ` web-0 ` Pod 处于 ** Running** (请参阅
243
250
[ Pod 阶段] ( /zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase ) )
244
251
并 ** Ready** (请参阅 [ Pod 状况] ( /zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions ) 中的
245
252
` type ` )状态后,` web-1 ` Pod 才会被启动。
246
253
254
+ 在本教程的后面部分,你将练习[ 并行启动] ( #parallel-pod-management ) 。
255
+
247
256
{{< note >}}
248
257
<!--
249
258
To configure the integer ordinal assigned to each Pod in a StatefulSet, see
@@ -497,11 +506,13 @@ Address 1: 10.244.2.8
497
506
The Pods' ordinals, hostnames, SRV records, and A record names have not changed,
498
507
but the IP addresses associated with the Pods may have changed. In the cluster
499
508
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).
501
511
-->
502
512
Pod 的序号、主机名、SRV 条目和记录名称没有改变,但和 Pod 相关联的 IP 地址可能发生了改变。
503
513
在本教程中使用的集群中它们就改变了。这就是为什么不要在其他应用中使用
504
- StatefulSet 中 Pod 的 IP 地址进行连接,这点很重要。
514
+ StatefulSet 中特定 Pod 的 IP 地址进行连接,这点很重要
515
+ (可以通过解析 Pod 的主机名来连接到 Pod)。
505
516
506
517
<!--
507
518
#### Discovery for specific Pods in a StatefulSet
@@ -531,6 +542,20 @@ to Running and Ready.
531
542
` web-1.nginx.default.svc.cluster.local ` )。因为它们是稳定的,并且当你的
532
543
Pod 的状态变为 Running 和 Ready 时,你的应用就能够发现它们的地址。
533
544
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
+
534
559
<!--
535
560
### Writing to stable Storage
536
561
-->
@@ -701,12 +726,13 @@ PersistentVolumeClaim 相关联的 PersistentVolume 卷被重新挂载到了各
701
726
## 扩容/缩容 StatefulSet {#scaling-a-statefulset}
702
727
703
728
<!--
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).
705
731
This is accomplished by updating the `replicas` field. You can use either
706
732
[`kubectl scale`](/docs/reference/generated/kubectl/kubectl-commands/#scale) or
707
733
[`kubectl patch`](/docs/reference/generated/kubectl/kubectl-commands/#patch) to scale a StatefulSet.
708
734
-->
709
- 扩容/缩容 StatefulSet 指增加或减少它的副本数。这通过更新 ` replicas ` 字段完成。
735
+ 扩容/缩容 StatefulSet 指增加或减少它的副本数。这通过更新 ` replicas ` 字段完成(水平缩放) 。
710
736
你可以使用 [ ` kubectl scale ` ] ( /docs/reference/generated/kubectl/kubectl-commands/#scale )
711
737
或者 [ ` kubectl patch ` ] ( /docs/reference/generated/kubectl/kubectl-commands/#patch ) 来扩容/缩容一个 StatefulSet。
712
738
@@ -715,6 +741,14 @@ This is accomplished by updating the `replicas` field. You can use either
715
741
-->
716
742
### 扩容 {#scaling-up}
717
743
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
+
718
752
<!--
719
753
In one terminal window, watch the Pods in the StatefulSet:
720
754
-->
@@ -793,6 +827,14 @@ Pod,并且会等待前一个 Pod 变为 Running 和 Ready 才会启动下一
793
827
-->
794
828
### 缩容 {#scaling-down}
795
829
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
+
796
838
<!--
797
839
In one terminal, watch the StatefulSet's Pods:
798
840
-->
@@ -854,9 +896,9 @@ web-3 1/1 Terminating 0 42s
854
896
### 顺序终止 Pod {#ordered-pod-termination}
855
897
856
898
<!--
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 .
860
902
-->
861
903
控制器会按照与 Pod 序号索引相反的顺序每次删除一个 Pod。在删除下一个 Pod 前会等待上一个被完全关闭。
862
904
@@ -879,12 +921,13 @@ www-web-4 Bound pvc-e11bb5f8-b508-11e6-932f-42010a800002 1Gi RWO
879
921
880
922
<!--
881
923
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.
885
928
-->
886
929
五个 PersistentVolumeClaims 和五个 PersistentVolume 卷仍然存在。
887
- 查看 Pod 的[ 稳定存储] ( #stable-storage ) ,我们发现当删除 StatefulSet 的
930
+ 查看 Pod 的[ 稳定存储] ( #stable-storage ) ,你会发现当删除 StatefulSet 的
888
931
Pod 时,挂载到 StatefulSet 的 Pod 的 PersistentVolume 卷不会被删除。
889
932
当这种删除行为是由 StatefulSet 缩容引起时也是一样的。
890
933
@@ -1802,13 +1845,12 @@ identity.
1802
1845
这些系统仅仅要求唯一性和身份标志。
1803
1846
1804
1847
<!--
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`.
1808
1850
-->
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 ` 。
1812
1854
1813
1855
<!--
1814
1856
### OrderedReady Pod management
@@ -1823,20 +1865,51 @@ above.
1823
1865
` OrderedReady ` Pod 管理策略是 StatefulSet 的默认选项。它告诉
1824
1866
StatefulSet 控制器遵循上文展示的顺序性保证。
1825
1867
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
+
1826
1889
<!--
1827
1890
### Parallel Pod management
1828
1891
-->
1829
1892
### Parallel Pod 管理策略 {#parallel-pod-management}
1830
1893
1831
1894
<!--
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.
1836
1899
-->
1837
- ` Parallel ` Pod 管理策略告诉 StatefulSet 控制器并行的终止所有 Pod,
1900
+ 另一种选择, ` Parallel ` Pod 管理策略告诉 StatefulSet 控制器并行的终止所有 Pod,
1838
1901
在启动或终止另一个 Pod 前,不必等待这些 Pod 变成 Running 和 Ready 或者完全终止状态。
1839
1902
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
+
1840
1913
{{% code_sample file="application/web/web-parallel.yaml" %}}
1841
1914
1842
1915
<!--
@@ -1860,80 +1933,67 @@ kubectl get pod -l app=nginx --watch
1860
1933
```
1861
1934
1862
1935
<!--
1863
- In another terminal, create the StatefulSet and Service in the manifest :
1936
+ In another terminal, reconfigure the StatefulSet for `Parallel` Pod management :
1864
1937
-->
1865
- 在另一个终端窗口创建清单中的 StatefulSet 和 Service :
1938
+ 在另一个终端中,重新配置 StatefulSet 以进行 ` Parallel ` Pod 管理 :
1866
1939
1867
1940
``` shell
1868
1941
kubectl apply -f https://k8s.io/examples/application/web/web-parallel.yaml
1869
1942
```
1870
1943
```
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
1897
1946
```
1898
1947
1899
1948
<!--
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
1907
1950
StatefulSet:
1908
1951
-->
1909
- 保持第二个终端打开 ,并在另一个终端窗口中扩容 StatefulSet:
1952
+ 保持你运行监视进程的终端为打开状态 ,并在另一个终端窗口中扩容 StatefulSet:
1910
1953
1911
1954
``` shell
1912
- kubectl scale statefulset/web --replicas=4
1955
+ kubectl scale statefulset/web --replicas=5
1913
1956
```
1914
1957
```
1915
1958
statefulset.apps/web scaled
1916
1959
```
1917
1960
1918
1961
<!--
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
1920
1963
-->
1921
- 在 ` kubectl get ` 命令运行的终端里检查它的输出。
1964
+ 在 ` kubectl get ` 命令运行的终端里检查它的输出。它可能看起来像:
1922
1965
1923
1966
```
1924
1967
web-3 0/1 Pending 0 0s
1925
1968
web-3 0/1 Pending 0 0s
1926
1969
web-3 0/1 Pending 0 7s
1927
1970
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
1929
1975
web-3 1/1 Running 0 26s
1976
+ web-4 1/1 Running 0 2s
1930
1977
```
1931
1978
1932
1979
<!--
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.
1935
1991
-->
1936
- StatefulSet 启动了两个新的 Pod,而且在启动第二个之前并没有等待第一个变成 Running 和 Ready 状态。
1992
+ 如果你的工作负载具有有状态元素,或者需要 Pod 能够通过可预测的命名来相互识别,
1993
+ 特别是当你有时需要快速提供更多容量时,此方法非常有用。
1994
+ 如果本教程的这个简单 Web 服务突然每分钟收到额外 1,000,000 个请求,
1995
+ 那么你可能会想要运行更多 Pod,但你也不想等待每个新 Pod 启动。
1996
+ 并行启动额外的 Pod 可以缩短请求额外容量和使其可供使用之间的时间。
1937
1997
1938
1998
## {{% heading "cleanup" %}}
1939
1999
0 commit comments