@@ -8,6 +8,8 @@ content_type: concept
8
8
weight : 10
9
9
---
10
10
<!--
11
+ reviewers:
12
+ - janetkuo
11
13
title: Deployments
12
14
feature:
13
15
title: Automated rollouts and rollbacks
@@ -80,7 +82,7 @@ The following are typical use cases for Deployments:
80
82
* [ 清理较旧的不再需要的 ReplicaSet] ( #clean-up-policy ) 。
81
83
82
84
<!--
83
- ## Creating a Deployment
85
+ ## Creating a Deployment
84
86
85
87
The following is an example of a Deployment. It creates a ReplicaSet to bring up three `nginx` Pods:
86
88
-->
@@ -97,8 +99,8 @@ In this example:
97
99
98
100
<!--
99
101
* A Deployment named `nginx-deployment` is created, indicated by the
100
- `.metadata.name` field. This name will become the basis for the ReplicaSets
101
- and Pods which are created later. See [Writing a Deployment Spec](#writing-a-deployment-spec)
102
+ `.metadata.name` field. This name will become the basis for the ReplicaSets
103
+ and Pods which are created later. See [Writing a Deployment Spec](#writing-a-deployment-spec)
102
104
for more details.
103
105
* The Deployment creates a ReplicaSet that creates three replicated Pods, indicated by the `.spec.replicas` field.
104
106
* The `.spec.selector` field defines how the created ReplicaSet finds which Pods to manage.
@@ -116,12 +118,12 @@ In this example:
116
118
117
119
{{< note >}}
118
120
<!--
119
- The `spec.selector.matchLabels` field is a map of {key,value} pairs.
121
+ The `. spec.selector.matchLabels` field is a map of {key,value} pairs.
120
122
A single {key,value} in the `matchLabels` map is equivalent to an element of `matchExpressions`,
121
123
whose `key` field is "key", the `operator` is "In", and the `values` array contains only "value".
122
124
All of the requirements, from both `matchLabels` and `matchExpressions`, must be satisfied in order to match.
123
125
-->
124
- ` spec.selector.matchLabels ` 字段是 ` {key,value} ` 键值对映射。
126
+ ` . spec.selector.matchLabels` 字段是 ` {key,value} ` 键值对映射。
125
127
在 ` matchLabels ` 映射中的每个 ` {key,value} ` 映射等效于 ` matchExpressions ` 中的一个元素,
126
128
即其 ` key ` 字段是 “key”,` operator ` 为 “In”,` values ` 数组仅包含 “value”。
127
129
在 ` matchLabels ` 和 ` matchExpressions ` 中给出的所有条件都必须满足才能匹配。
@@ -158,9 +160,9 @@ Follow the steps given below to create the above Deployment:
158
160
```
159
161
160
162
<!--
161
- 2. Run `kubectl get deployments` to check if the Deployment was created.
163
+ 2. Run `kubectl get deployments` to check if the Deployment was created.
162
164
163
- If the Deployment is still being created, the output is similar to the following:
165
+ If the Deployment is still being created, the output is similar to the following:
164
166
-->
165
167
2 . 运行 ` kubectl get deployments ` 检查 Deployment 是否已创建。
166
168
如果仍在创建 Deployment,则输出类似于:
@@ -208,7 +210,7 @@ Follow the steps given below to create the above Deployment:
208
210
```
209
211
210
212
<!--
211
- 4. Run the `kubectl get deployments` again a few seconds later.
213
+ 4. Run the `kubectl get deployments` again a few seconds later.
212
214
The output is similar to this:
213
215
-->
214
216
4 . 几秒钟后再次运行 ` kubectl get deployments ` 。输出类似于:
@@ -255,7 +257,7 @@ Follow the steps given below to create the above Deployment:
255
257
256
258
<!--
257
259
Notice that the name of the ReplicaSet is always formatted as
258
- `[DEPLOYMENT-NAME]-[HASH]`. This name will become the basis for the Pods
260
+ `[DEPLOYMENT-NAME]-[HASH]`. This name will become the basis for the Pods
259
261
which are created.
260
262
The `HASH` string is the same as the `pod-template-hash` label on the ReplicaSet.
261
263
-->
@@ -296,7 +298,7 @@ Kubernetes 不会阻止你这样做,但是如果多个控制器具有重叠的
296
298
{{< /note >}}
297
299
298
300
<!--
299
- ### Pod-template-hash label
301
+ ### Pod-template-hash label
300
302
-->
301
303
### Pod-template-hash 标签
302
304
@@ -323,13 +325,13 @@ and in any existing Pods that the ReplicaSet might have.
323
325
可能拥有的任何现有 Pod 中。
324
326
325
327
<!--
326
- ## Updating a Deployment
328
+ ## Updating a Deployment
327
329
-->
328
330
## 更新 Deployment {#updating-a-deployment}
329
331
330
332
{{< note >}}
331
333
<!--
332
- A Deployment's rollout is triggered if and only if the Deployment's Pod template (that is, `.spec.template`)
334
+ A Deployment's rollout is triggered if and only if the Deployment's Pod template (that is, `.spec.template`)
333
335
is changed, for example if the labels or container images of the template are updated. Other updates, such as scaling the Deployment, do not trigger a rollout.
334
336
-->
335
337
仅当 Deployment Pod 模板(即 ` .spec.template ` )发生改变时,例如模板的标签或容器镜像被更新,
@@ -353,7 +355,7 @@ Follow the steps given below to update your Deployment:
353
355
or use the following command:
354
356
-->
355
357
或者使用下面的命令:
356
-
358
+
357
359
``` shell
358
360
kubectl set image deployment/nginx-deployment nginx=nginx:1.16.1
359
361
```
@@ -492,7 +494,7 @@ up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas.
492
494
then deletes an old Pod, and creates another new one. It does not kill old Pods until a sufficient number of
493
495
new Pods have come up, and does not create new Pods until a sufficient number of old Pods have been killed.
494
496
It makes sure that at least 3 Pods are available and that at max 4 Pods in total are available. In case of
495
- a Deployment with 4 replicas, the number of Pods would be between 3 and 5.
497
+ a Deployment with 4 replicas, the number of Pods would be between 3 and 5.
496
498
-->
497
499
例如,如果仔细查看上述 Deployment ,将看到它首先创建了一个新的 Pod,然后删除旧的 Pod,
498
500
并创建了新的 Pod。它不会杀死旧 Pod,直到有足够数量的新 Pod 已经出现。
@@ -559,8 +561,7 @@ up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas.
559
561
(nginx-deployment-1564180365) and scaled it up to 1 and waited for it to come up. Then it scaled down the old ReplicaSet
560
562
to 2 and scaled up the new ReplicaSet to 2 so that at least 3 Pods were available and at most 4 Pods were created at all times.
561
563
It then continued scaling up and down the new and the old ReplicaSet, with the same rolling update strategy.
562
- Finally, you'll have 3 available replicas
563
- in the new ReplicaSet, and the old ReplicaSet is scaled down to 0.
564
+ Finally, you'll have 3 available replicas in the new ReplicaSet, and the old ReplicaSet is scaled down to 0.
564
565
-->
565
566
可以看到,当第一次创建 Deployment 时,它创建了一个 ReplicaSet(` nginx-deployment-2035384211 ` )
566
567
并将其直接扩容至 3 个副本。更新 Deployment 时,它创建了一个新的 ReplicaSet
@@ -624,7 +625,7 @@ before changing course.
624
625
<!--
625
626
### Label selector updates
626
627
627
- It is generally discouraged to make label selector updates and it is suggested to plan your selectors up front.
628
+ It is generally discouraged to make label selector updates and it is suggested to plan your selectors up front.
628
629
In any case, if you need to perform a label selector update, exercise great caution and make sure you have grasped
629
630
all of the implications.
630
631
-->
@@ -665,7 +666,7 @@ removed label still exists in any existing Pods and ReplicaSets.
665
666
## 回滚 Deployment {#rolling-back-a-deployment}
666
667
667
668
<!--
668
- Sometimes, you may want to rollback a Deployment; for example, when the Deployment is not stable, such as crash looping.
669
+ Sometimes, you may want to rollback a Deployment; for example, when the Deployment is not stable, such as crash looping.
669
670
By default, all of the Deployment's rollout history is kept in the system so that you can rollback anytime you want
670
671
(you can change that by modifying revision history limit).
671
672
-->
@@ -697,7 +698,7 @@ Deployment 被触发上线时,系统就会创建 Deployment 的新的修订版
697
698
` nginx:1.161 ` 而不是 ` nginx:1.16.1 ` :
698
699
699
700
``` shell
700
- kubectl set image deployment/nginx-deployment nginx=nginx:1.161
701
+ kubectl set image deployment/nginx-deployment nginx=nginx:1.161
701
702
```
702
703
703
704
<!--
@@ -734,7 +735,7 @@ Deployment 被触发上线时,系统就会创建 Deployment 的新的修订版
734
735
* 按 Ctrl-C 停止上述上线状态观测。有关上线停滞的详细信息,[ 参考这里] ( #deployment-status ) 。
735
736
736
737
<!--
737
- * You see that the number of old replicas (`nginx-deployment-1564180365` and `nginx-deployment-2035384211`) is 2, and new replicas (nginx-deployment-3066724191) is 1.
738
+ * You see that the number of old replicas (`nginx-deployment-1564180365` and `nginx-deployment-2035384211`) is 2, and new replicas (nginx-deployment-3066724191) is 1.
738
739
-->
739
740
* 你可以看到旧的副本有两个(` nginx-deployment-1564180365 ` 和 ` nginx-deployment-2035384211 ` ),
740
741
新的副本有 1 个(` nginx-deployment-3066724191 ` ):
@@ -748,7 +749,7 @@ Deployment 被触发上线时,系统就会创建 Deployment 的新的修订版
748
749
-->
749
750
输出类似于:
750
751
751
- ``` shell
752
+ ```
752
753
NAME DESIRED CURRENT READY AGE
753
754
nginx-deployment-1564180365 3 3 3 25s
754
755
nginx-deployment-2035384211 0 0 0 36s
@@ -769,7 +770,7 @@ Deployment 被触发上线时,系统就会创建 Deployment 的新的修订版
769
770
-->
770
771
输出类似于:
771
772
772
- ``` shell
773
+ ```
773
774
NAME READY STATUS RESTARTS AGE
774
775
nginx-deployment-1564180365-70iae 1/1 Running 0 25s
775
776
nginx-deployment-1564180365-jbqqo 1/1 Running 0 25s
@@ -828,7 +829,7 @@ Deployment 被触发上线时,系统就会创建 Deployment 的新的修订版
828
829
OldReplicaSets: nginx-deployment-1564180365 (3/3 replicas created)
829
830
NewReplicaSet: nginx-deployment-3066724191 (1/1 replicas created)
830
831
Events:
831
- FirstSeen LastSeen Count From SubobjectPath Type Reason Message
832
+ FirstSeen LastSeen Count From SubObjectPath Type Reason Message
832
833
--------- -------- ----- ---- ------------- -------- ------ -------
833
834
1m 1m 1 {deployment-controller } Normal ScalingReplicaSet Scaled up replica set nginx-deployment-2035384211 to 3
834
835
22s 22s 1 {deployment-controller } Normal ScalingReplicaSet Scaled up replica set nginx-deployment-1564180365 to 1
@@ -855,7 +856,7 @@ Follow the steps given below to check the rollout history:
855
856
按照如下步骤检查回滚历史:
856
857
857
858
<!--
858
- 1. First, check the revisions of this Deployment:
859
+ 1. First, check the revisions of this Deployment:
859
860
-->
860
861
1 . 首先,检查 Deployment 修订历史:
861
862
@@ -929,7 +930,7 @@ Follow the steps given below to rollback the Deployment from the current version
929
930
按照下面给出的步骤将 Deployment 从当前版本回滚到以前的版本(即版本 2)。
930
931
931
932
<!--
932
- 1. Now you've decided to undo the current rollout and rollback to the previous revision:
933
+ 1. Now you've decided to undo the current rollout and rollback to the previous revision:
933
934
-->
934
935
1 . 假定现在你已决定撤消当前上线并回滚到以前的修订版本:
935
936
@@ -1229,7 +1230,7 @@ The output is similar to this:
1229
1230
-->
1230
1231
输出类似于:
1231
1232
1232
- ``` shell
1233
+ ```
1233
1234
NAME DESIRED CURRENT READY AGE
1234
1235
nginx-deployment-1989198191 7 7 0 7m
1235
1236
nginx-deployment-618515232 11 11 11 7m
@@ -1307,7 +1308,7 @@ apply multiple fixes in between pausing and resuming without triggering unnecess
1307
1308
-->
1308
1309
输出类似于:
1309
1310
1310
- ``` shell
1311
+ ```
1311
1312
deployment.apps/nginx-deployment paused
1312
1313
```
1313
1314
@@ -1363,7 +1364,7 @@ apply multiple fixes in between pausing and resuming without triggering unnecess
1363
1364
-->
1364
1365
输出类似于:
1365
1366
1366
- ``` shell
1367
+ ```
1367
1368
NAME DESIRED CURRENT READY AGE
1368
1369
nginx-2142116321 3 3 3 2m
1369
1370
```
@@ -1388,7 +1389,8 @@ apply multiple fixes in between pausing and resuming without triggering unnecess
1388
1389
1389
1390
<!--
1390
1391
The initial state of the Deployment prior to pausing its rollout will continue its function, but new updates to
1391
- the Deployment will not have any effect as long as the Deployment is paused.
1392
+ the Deployment will not have any effect as long as the Deployment rollout is paused.
1393
+
1392
1394
-->
1393
1395
暂停 Deployment 上线之前的初始状态将继续发挥作用,但新的更新在 Deployment
1394
1396
上线被暂停期间不会产生任何效果。
@@ -1573,7 +1575,7 @@ The output is similar to this:
1573
1575
-->
1574
1576
输出类似于:
1575
1577
1576
- ``` shell
1578
+ ```
1577
1579
Waiting for rollout to finish: 2 of 3 updated replicas are available...
1578
1580
deployment "nginx-deployment" successfully rolled out
1579
1581
```
@@ -1584,7 +1586,7 @@ and the exit status from `kubectl rollout` is 0 (success):
1584
1586
从 ` kubectl rollout ` 命令获得的返回状态为 0(成功):
1585
1587
1586
1588
``` shell
1587
- $ echo $?
1589
+ echo $?
1588
1590
```
1589
1591
```
1590
1592
0
@@ -1603,7 +1605,7 @@ due to some of the following factors:
1603
1605
造成此情况一些可能因素如下:
1604
1606
1605
1607
<!--
1606
- * Insufficient quota
1608
+ * Insufficient quota
1607
1609
* Readiness probe failures
1608
1610
* Image pull errors
1609
1611
* Insufficient permissions
@@ -1676,7 +1678,7 @@ See the [Kubernetes API conventions](https://git.k8s.io/community/contributors/d
1676
1678
1677
1679
{{< note >}}
1678
1680
<!--
1679
- Kubernetes takes no action on a stalled Deployment other than to report a status condition with
1681
+ Kubernetes takes no action on a stalled Deployment other than to report a status condition with
1680
1682
`reason: ProgressDeadlineExceeded`. Higher level orchestrators can take advantage of it and act accordingly, for
1681
1683
example, rollback the Deployment to its previous version.
1682
1684
-->
@@ -1687,8 +1689,8 @@ Deployment 不执行任何操作。更高级别的编排器可以利用这一设
1687
1689
1688
1690
{{< note >}}
1689
1691
<!--
1690
- If you pause a Deployment rollout, Kubernetes does not check progress against your specified deadline.
1691
- You can safely pause a Deployment rollout in the middle of a rollout and resume without triggering
1692
+ If you pause a Deployment rollout, Kubernetes does not check progress against your specified deadline.
1693
+ You can safely pause a Deployment rollout in the middle of a rollout and resume without triggering
1692
1694
the condition for exceeding the deadline.
1693
1695
-->
1694
1696
如果你暂停了某个 Deployment 上线,Kubernetes 不再根据指定的截止时间检查 Deployment 上线的进展。
@@ -1831,7 +1833,7 @@ and the exit status from `kubectl rollout` is 1 (indicating an error):
1831
1833
` kubectl rollout ` 命令的退出状态为 1(表明发生了错误):
1832
1834
1833
1835
``` shell
1834
- $ echo $?
1836
+ echo $?
1835
1837
```
1836
1838
```
1837
1839
1
@@ -1899,9 +1901,9 @@ configuring containers, and [using kubectl to manage resources](/docs/concepts/o
1899
1901
1900
1902
<!--
1901
1903
When the control plane creates new Pods for a Deployment, the `.metadata.name` of the
1902
- Deployment is part of the basis for naming those Pods. The name of a Deployment must be a valid
1904
+ Deployment is part of the basis for naming those Pods. The name of a Deployment must be a valid
1903
1905
[DNS subdomain](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names)
1904
- value, but this can produce unexpected results for the Pod hostnames. For best compatibility,
1906
+ value, but this can produce unexpected results for the Pod hostnames. For best compatibility,
1905
1907
the name should follow the more restrictive rules for a
1906
1908
[DNS label](/docs/concepts/overview/working-with-objects/names#dns-label-names).
1907
1909
@@ -2056,11 +2058,11 @@ All existing Pods are killed before new ones are created when `.spec.strategy.ty
2056
2058
2057
2059
{{< note >}}
2058
2060
<!--
2059
- This will only guarantee Pod termination previous to creation for upgrades. If you upgrade a Deployment, all Pods
2060
- of the old revision will be terminated immediately. Successful removal is awaited before any Pod of the new
2061
- revision is created. If you manually delete a Pod, the lifecycle is controlled by the ReplicaSet and the
2062
- replacement will be created immediately (even if the old Pod is still in a Terminating state). If you need an
2063
- "at most" guarantee for your Pods, you should consider using a
2061
+ This will only guarantee Pod termination previous to creation for upgrades. If you upgrade a Deployment, all Pods
2062
+ of the old revision will be terminated immediately. Successful removal is awaited before any Pod of the new
2063
+ revision is created. If you manually delete a Pod, the lifecycle is controlled by the ReplicaSet and the
2064
+ replacement will be created immediately (even if the old Pod is still in a Terminating state). If you need an
2065
+ "at most" guarantee for your Pods, you should consider using a
2064
2066
[StatefulSet](/docs/concepts/workloads/controllers/statefulset/).
2065
2067
-->
2066
2068
这只会确保为了升级而创建新 Pod 之前其他 Pod 都已终止。如果你升级一个 Deployment,
@@ -2114,7 +2116,7 @@ at all times during the update is at least 70% of the desired Pods.
2114
2116
<!--
2115
2117
##### Max Surge
2116
2118
2117
- `.spec.strategy.rollingUpdate.maxSurge` is an optional field that specifies the maximum number of Pods
2119
+ `.spec.strategy.rollingUpdate.maxSurge` is an optional field that specifies the maximum number of Pods
2118
2120
that can be created over the desired number of Pods. The value can be an absolute number (for example, 5) or a
2119
2121
percentage of desired Pods (for example, 10%). The value cannot be 0 if `MaxUnavailable` is 0. The absolute number
2120
2122
is calculated from the percentage by rounding up. The default value is 25%.
@@ -2137,11 +2139,11 @@ total number of Pods running at any time during the update is at most 130% of de
2137
2139
同时确保更新期间的任何时候运行中的 Pod 总数最多为所需 Pod 总数的 130%。
2138
2140
2139
2141
<!--
2140
- ### Progress Deadline Seconds
2142
+ ### Progress Deadline Seconds
2141
2143
2142
- `.spec.progressDeadlineSeconds` is an optional field that specifies the number of seconds you want
2144
+ `.spec.progressDeadlineSeconds` is an optional field that specifies the number of seconds you want
2143
2145
to wait for your Deployment to progress before the system reports back that the Deployment has
2144
- [failed progressing](#failed-deployment) - surfaced as a condition with `type: Progressing`, `status: False`.
2146
+ [failed progressing](#failed-deployment) - surfaced as a condition with `type: Progressing`, `status: " False" `.
2145
2147
and `reason: ProgressDeadlineExceeded` in the status of the resource. The Deployment controller will keep
2146
2148
retrying the Deployment. This defaults to 600. In the future, once automatic rollback will be implemented, the Deployment
2147
2149
controller will roll back a Deployment as soon as it observes such a condition.
@@ -2162,7 +2164,7 @@ If specified, this field needs to be greater than `.spec.minReadySeconds`.
2162
2164
<!--
2163
2165
### Min Ready Seconds
2164
2166
2165
- `.spec.minReadySeconds` is an optional field that specifies the minimum number of seconds for which a newly
2167
+ `.spec.minReadySeconds` is an optional field that specifies the minimum number of seconds for which a newly
2166
2168
created Pod should be ready without any of its containers crashing, for it to be considered available.
2167
2169
This defaults to 0 (the Pod will be considered available as soon as it is ready). To learn more about when
2168
2170
a Pod is considered ready, see [Container Probes](/docs/concepts/workloads/pods/pod-lifecycle/#container-probes).
0 commit comments