@@ -146,8 +146,11 @@ of the StatefulSet's Pods.
146
146
来{{< glossary_tooltip text="监视" term_id="watch" >}} StatefulSet 的 Pod 的创建情况。
147
147
148
148
<!--
149
+ ```shell
149
150
# use this terminal to run commands that specify --watch
150
151
# end this watch when you are asked to start a new watch
152
+ kubectl get pods --watch -l app=nginx
153
+ ```
151
154
-->
152
155
``` shell
153
156
# 使用此终端运行指定 --watch 的命令
@@ -175,7 +178,7 @@ statefulset.apps/web created
175
178
The command above creates two Pods, each running an
176
179
[NGINX](https://www.nginx.com) webserver. Get the `nginx` Service...
177
180
-->
178
- 上面的命令创建了两个 Pod,每个都运行了一个 [ NginX ] ( https://www.nginx.com ) Web 服务器。
181
+ 上面的命令创建了两个 Pod,每个都运行了一个 [ NGINX ] ( https://www.nginx.com ) Web 服务器。
179
182
获取 ` nginx ` Service:
180
183
181
184
``` shell
@@ -219,8 +222,11 @@ look like the example below.
219
222
在第一个终端中使用 ` kubectl get ` 检查输出。这个输出最终将看起来像下面的样子。
220
223
221
224
<!--
225
+ ```shell
222
226
# Do not start a new watch;
223
227
# this should already be running
228
+ kubectl get pods --watch -l app=nginx
229
+ ```
224
230
-->
225
231
``` shell
226
232
# 不要开始一个新的 watch
@@ -392,8 +398,11 @@ In one terminal, watch the StatefulSet's Pods:
392
398
在一个终端中监视 StatefulSet 的 Pod:
393
399
394
400
<!--
401
+ ```shell
395
402
# Start a new watch
396
403
# End this watch when you've seen that the delete is finished
404
+ kubectl get pod --watch -l app=nginx
405
+ ```
397
406
-->
398
407
``` shell
399
408
# 启动一个新的 watch
@@ -425,7 +434,10 @@ Running and Ready:
425
434
等待 StatefulSet 重启它们,并且两个 Pod 都变成 Running 和 Ready 状态:
426
435
427
436
<!--
437
+ ```shell
428
438
# This should already be running
439
+ kubectl get pod --watch -l app=nginx
440
+ ```
429
441
-->
430
442
``` shell
431
443
# 这应该已经处于 Running 状态
@@ -472,6 +484,12 @@ In that new shell, run:
472
484
-->
473
485
这将启动一个新的 Shell。在新 Shell 中,运行:
474
486
487
+ <!--
488
+ ```shell
489
+ # Run this in the dns-test container shell
490
+ nslookup web-0.nginx
491
+ ```
492
+ -->
475
493
``` shell
476
494
# 在 dns-test 容器 Shell 中运行以下命令
477
495
nslookup web-0.nginx
@@ -659,8 +677,12 @@ In a second terminal, delete all of the StatefulSet's Pods:
659
677
在另一个终端删除 StatefulSet 所有的 Pod:
660
678
661
679
<!--
680
+ ```shell
662
681
# End this watch when you've reached the end of the section.
663
682
# At the start of "Scaling a StatefulSet" you'll start a new watch.
683
+ kubectl get pod --watch -l app=nginx
684
+ ```
685
+ -->
664
686
-->
665
687
``` shell
666
688
# 当你到达该部分的末尾时结束此 watch
@@ -679,7 +701,10 @@ for all of the Pods to transition to Running and Ready.
679
701
在第一个终端里检查 ` kubectl get ` 命令的输出,等待所有 Pod 变成 Running 和 Ready 状态。
680
702
681
703
<!--
704
+ ```shell
682
705
# This should already be running
706
+ kubectl get pod --watch -l app=nginx
707
+ ```
683
708
-->
684
709
``` shell
685
710
# 这应该已经处于 Running 状态
@@ -734,7 +759,8 @@ This is accomplished by updating the `replicas` field. You can use either
734
759
-->
735
760
扩容/缩容 StatefulSet 指增加或减少它的副本数。这通过更新 ` replicas ` 字段完成(水平缩放)。
736
761
你可以使用 [ ` kubectl scale ` ] ( /docs/reference/generated/kubectl/kubectl-commands/#scale )
737
- 或者 [ ` kubectl patch ` ] ( /docs/reference/generated/kubectl/kubectl-commands/#patch ) 来扩容/缩容一个 StatefulSet。
762
+ 或者 [ ` kubectl patch ` ] ( /docs/reference/generated/kubectl/kubectl-commands/#patch )
763
+ 来扩容/缩容一个 StatefulSet。
738
764
739
765
<!--
740
766
### Scaling up
@@ -755,9 +781,12 @@ In one terminal window, watch the Pods in the StatefulSet:
755
781
在一个终端窗口监视 StatefulSet 的 Pod:
756
782
757
783
<!--
784
+ ```shell
758
785
# If you already have a watch running, you can continue using that.
759
786
# Otherwise, start one.
760
787
# End this watch when there are 5 healthy Pods for the StatefulSet
788
+ kubectl get pods --watch -l app=nginx
789
+ ```
761
790
-->
762
791
``` shell
763
792
# 如果你已经有一个正在运行的 wach,你可以继续使用它。
@@ -786,7 +815,10 @@ for the three additional Pods to transition to Running and Ready.
786
815
在第一个 终端中检查 ` kubectl get ` 命令的输出,等待增加的 3 个 Pod 的状态变为 Running 和 Ready。
787
816
788
817
<!--
818
+ ```shell
789
819
# This should already be running
820
+ kubectl get pod --watch -l app=nginx
821
+ ```
790
822
-->
791
823
``` shell
792
824
# 这应该已经处于 Running 状态
@@ -841,7 +873,11 @@ In one terminal, watch the StatefulSet's Pods:
841
873
在一个终端监视 StatefulSet 的 Pod:
842
874
843
875
<!--
876
+ ```shell
877
+ kubectl get pods -w -l app=nginx
844
878
# End this watch when there are only 3 Pods for the StatefulSet
879
+ kubectl get pod --watch -l app=nginx
880
+ ```
845
881
-->
846
882
``` shell
847
883
kubectl get pods -w -l app=nginx
@@ -868,7 +904,11 @@ Wait for `web-4` and `web-3` to transition to Terminating.
868
904
等待 ` web-4 ` 和 ` web-3 ` 状态变为 Terminating。
869
905
870
906
<!--
907
+ ```shell
908
+ kubectl get pods -w -l app=nginx
871
909
# This should already be running
910
+ kubectl get pods --watch -l app=nginx
911
+ ```
872
912
-->
873
913
``` shell
874
914
kubectl get pods -w -l app=nginx
@@ -973,7 +1013,7 @@ You'll practice that later in this tutorial.
973
1013
First, try a simple rolling update.
974
1014
-->
975
1015
你可以通过指定 ` .spec.updateStrategy.rollingUpdate.partition ` 将使用 ` RollingUpdate `
976
- 策略的 StatefulSet 的更新拆分为多个** 分区** 。你将在本教程中稍后练习此操作。
1016
+ 策略的 StatefulSet 的更新拆分为多个** 分区** 。你将在本教程中稍后练习此操作。
977
1017
978
1018
首先,尝试一个简单的滚动更新。
979
1019
@@ -996,9 +1036,12 @@ In another terminal, watch the Pods in the StatefulSet:
996
1036
在另一个终端监控 StatefulSet 中的 Pod:
997
1037
998
1038
<!--
1039
+ ```shell
999
1040
# End this watch when the rollout is complete
1000
1041
#
1001
1042
# If you're not sure, leave it running one more minute
1043
+ kubectl get pod -l app=nginx --watch
1044
+ ```
1002
1045
-->
1003
1046
``` shell
1004
1047
# 滚动完成后结束此 watch
@@ -1107,7 +1150,7 @@ You can split updates to a StatefulSet that uses the `RollingUpdate` strategy
1107
1150
into _partitions_, by specifying `.spec.updateStrategy.rollingUpdate.partition`.
1108
1151
-->
1109
1152
你可以通过指定 ` .spec.updateStrategy.rollingUpdate.partition ` 将使用 ` RollingUpdate ` 策略的
1110
- StatefulSet 的更新拆分为多个** 分区** 。
1153
+ StatefulSet 的更新拆分为多个** 分区** 。
1111
1154
1112
1155
<!--
1113
1156
For more context, you can read [Partitioned rolling updates](/docs/concepts/workloads/controllers/statefulset/#partitions)
@@ -1134,14 +1177,17 @@ First, patch the `web` StatefulSet to add a partition to the `updateStrategy` fi
1134
1177
对 ` web ` StatefulSet 执行 Patch 操作,为 ` updateStrategy ` 字段添加一个分区:
1135
1178
1136
1179
<!--
1180
+ ```shell
1137
1181
# The value of "partition" determines which ordinals a change applies to
1138
1182
# Make sure to use a number bigger than the last ordinal for the
1139
1183
# StatefulSet
1184
+ kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"OnDelete", "rollingUpdate": null}}}'
1185
+ ```
1140
1186
-->
1141
1187
``` shell
1142
1188
# "partition" 的值决定更改适用于哪些序号
1143
1189
# 确保使用比 StatefulSet 的最后一个序号更大的数字
1144
- kubectl patch statefulset web -p ' {"spec":{"updateStrategy":{"type":"RollingUpdate", "rollingUpdate":{"partition":3} }}}'
1190
+ kubectl patch statefulset web -p ' {"spec":{"updateStrategy":{"type":"OnDelete", "rollingUpdate": null }}}'
1145
1191
```
1146
1192
```
1147
1193
statefulset.apps/web patched
@@ -1178,7 +1224,10 @@ Wait for the replacement `web-2` Pod to be Running and Ready:
1178
1224
等待替代的 Pod 变成 Running 和 Ready。
1179
1225
1180
1226
<!--
1227
+ ```shell
1181
1228
# End the watch when you see that web-2 is healthy
1229
+ kubectl get pod -l app=nginx --watch
1230
+ ```
1182
1231
-->
1183
1232
``` shell
1184
1233
# 当你看到 web-2 运行正常时结束 watch
@@ -1236,8 +1285,11 @@ Patch the StatefulSet to decrement the partition:
1236
1285
通过 patch 命令修改 StatefulSet 来减少分区:
1237
1286
1238
1287
<!--
1288
+ ```shell
1239
1289
# The value of "partition" should match the highest existing ordinal for
1240
1290
# the StatefulSet
1291
+ kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"partition":2}}}}'
1292
+ ```
1241
1293
-->
1242
1294
``` shell
1243
1295
# “partition” 的值应与 StatefulSet 现有的最高序号相匹配
@@ -1253,11 +1305,12 @@ a graceful **delete** followed by creating a new Pod once the deletion
1253
1305
is complete).
1254
1306
Wait for the new `web-2` Pod to be Running and Ready.
1255
1307
-->
1256
- 控制平面会触发 ` web-2 ` 的替换(先优雅地 ** 删除** 现有 Pod,然后在删除完成后创建一个新的 Pod)。
1308
+ 控制平面会触发 ` web-2 ` 的替换(先优雅地** 删除** 现有 Pod,然后在删除完成后创建一个新的 Pod)。
1257
1309
等待新的 ` web-2 ` Pod 变成 Running 和 Ready。
1258
1310
1259
1311
<!--
1260
1312
# This should already be running
1313
+ kubectl get pod -l app=nginx --watch
1261
1314
-->
1262
1315
``` shell
1263
1316
# 这应该已经处于 Running 状态
@@ -1309,7 +1362,10 @@ Wait for the `web-1` Pod to be Running and Ready.
1309
1362
等待 ` web-1 ` 变成 Running 和 Ready。
1310
1363
1311
1364
<!--
1365
+ ```shell
1312
1366
# This should already be running
1367
+ kubectl get pod -l app=nginx --watch
1368
+ ```
1313
1369
-->
1314
1370
``` shell
1315
1371
# 这应该已经处于 Running 状态
@@ -1393,7 +1449,10 @@ Wait for all of the Pods in the StatefulSet to become Running and Ready.
1393
1449
等待 StatefulSet 中的所有 Pod 变成 Running 和 Ready。
1394
1450
1395
1451
<!--
1452
+ ```shell
1396
1453
# This should already be running
1454
+ kubectl get pod -l app=nginx --watch
1455
+ ```
1397
1456
-->
1398
1457
``` shell
1399
1458
# 这应该已经处于 Running 状态
@@ -1506,9 +1565,12 @@ In one terminal window, watch the Pods in the StatefulSet.
1506
1565
在一个终端窗口监视 StatefulSet 中的 Pod。
1507
1566
1508
1567
<!--
1568
+ ```
1509
1569
# End this watch when there are no Pods for the StatefulSet
1510
- -->
1570
+ kubectl get pods --watch -l app=nginx
1511
1571
```
1572
+ -->
1573
+ ``` shell
1512
1574
# 当 StatefulSet 没有 Pod 时结束此 watch
1513
1575
kubectl get pods --watch -l app=nginx
1514
1576
```
@@ -1549,7 +1611,7 @@ web-2 1/1 Running 0 5m
1549
1611
Even though `web` has been deleted, all of the Pods are still Running and Ready.
1550
1612
Delete `web-0`:
1551
1613
-->
1552
- 虽然 ` web ` 已经被删除了,但所有 Pod 仍然处于 Running 和 Ready 状态。
1614
+ 虽然 ` web ` 已经被删除了,但所有 Pod 仍然处于 Running 和 Ready 状态。
1553
1615
删除 ` web-0 ` :
1554
1616
1555
1617
``` shell
@@ -1584,7 +1646,10 @@ In one terminal, watch the StatefulSet's Pods.
1584
1646
在一个终端监控 StatefulSet 的 Pod。
1585
1647
1586
1648
<!--
1649
+ ```shell
1587
1650
# Leave this watch running until the next time you start a watch
1651
+ kubectl get pods --watch -l app=nginx
1652
+ ```
1588
1653
-->
1589
1654
``` shell
1590
1655
# 让 watch 一直运行到你下次启动 watch 为止
@@ -1620,7 +1685,10 @@ Examine the output of the `kubectl get` command running in the first terminal.
1620
1685
在第一个终端中运行并检查 ` kubectl get ` 命令的输出。
1621
1686
1622
1687
<!--
1688
+ ```shell
1623
1689
# This should already be running
1690
+ kubectl get pods --watch -l app=nginx
1691
+ ```
1624
1692
-->
1625
1693
``` shell
1626
1694
# 这应该已经处于 Running 状态
@@ -1719,7 +1787,10 @@ and wait for all of the Pods to transition to Terminating.
1719
1787
在第一个终端检查 ` kubectl get ` 命令的输出,并等待所有的 Pod 变成 Terminating 状态。
1720
1788
1721
1789
<!--
1790
+ ```shell
1722
1791
# This should already be running
1792
+ kubectl get pods --watch -l app=nginx
1793
+ ```
1723
1794
-->
1724
1795
``` shell
1725
1796
# 这应该已经处于 Running 状态
@@ -1925,7 +1996,10 @@ In one terminal, watch the Pods in the StatefulSet.
1925
1996
在一个终端窗口监视 StatefulSet 中的 Pod。
1926
1997
1927
1998
<!--
1999
+ ```shell
1928
2000
# Leave this watch running until the end of the section
2001
+ kubectl get pod -l app=nginx --watch
2002
+ ```
1929
2003
-->
1930
2004
``` shell
1931
2005
# 让 watch 一直运行直到本节结束
@@ -2003,18 +2077,27 @@ part of cleanup.
2003
2077
-->
2004
2078
你应该打开两个终端,准备在清理过程中运行 ` kubectl ` 命令。
2005
2079
2080
+ <!--
2006
2081
```shell
2007
2082
kubectl delete sts web
2008
2083
# sts is an abbreviation for statefulset
2009
2084
```
2085
+ -->
2086
+ ``` shell
2087
+ kubectl delete sts web
2088
+ # sts 是 statefulset 的缩写
2089
+ ```
2010
2090
2011
2091
<!--
2012
2092
You can watch `kubectl get` to see those Pods being deleted.
2013
2093
-->
2014
2094
你可以监视 ` kubectl get ` 来查看那些 Pod 被删除:
2015
2095
2016
2096
<!--
2097
+ ```shell
2017
2098
# end the watch when you've seen what you need to
2099
+ kubectl get pod -l app=nginx --watch
2100
+ ```
2018
2101
-->
2019
2102
``` shell
2020
2103
# 当你看到需要的内容后结束 watch
0 commit comments