diff --git a/content/zh/docs/concepts/workloads/controllers/deployment.md b/content/zh/docs/concepts/workloads/controllers/deployment.md index 6b7b633386..007eaf9771 100644 --- a/content/zh/docs/concepts/workloads/controllers/deployment.md +++ b/content/zh/docs/concepts/workloads/controllers/deployment.md @@ -144,16 +144,16 @@ The following is an example of a Deployment. It creates a ReplicaSet to bring up * `selector` 字段定义 Deployment 如何查找要管理的 Pods。 在这种情况下,只需选择在 Pod 模板(`app: nginx`)中定义的标签。但是,更复杂的选择规则是可能的,只要 Pod 模板本身满足规则。 -{{< note >}} + {{< note >}} - + --> `matchLabels` 字段是 {key,value} 的映射。单个 {key,value}在 `matchLabels` 映射中的值等效于 `matchExpressions` 的元素,其键字段是“key”,运算符为“In”,值数组仅包含“value”。所有要求,从 `matchLabels` 和 `matchExpressions`,必须满足才能匹配。 -{{< /note >}} + {{< /note >}} * Pod 标记为`app: nginx`,使用`labels`字段。 - + * Pod 模板规范或 `.template.spec` 字段指示 Pods 运行一个容器, `nginx`,运行 `nginx` [Docker Hub](https://hub.docker.com/)版本1.7.9的镜像 。 - + * 创建一个容器并使用`name`字段将其命名为 `nginx`。 - 按照以下步骤创建上述 Deployment : +按照以下步骤创建上述 Deployment : - 开始之前,请确保的 Kubernetes 集群已启动并运行。 +开始之前,请确保的 Kubernetes 集群已启动并运行。 - 1. 通过运行以下命令创建 Deployment : +1. 通过运行以下命令创建 Deployment : -{{< note >}} - + {{< note >}} + 可以指定 `--record` 标志来写入在资源注释`kubernetes.io/change-cause`中执行的命令。它对以后的检查是有用的。 - + 例如,查看在每个 Deployment 修改中执行的命令。 -{{< /note >}} + {{< /note >}} ```shell kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml @@ -210,42 +210,42 @@ The following is an example of a Deployment. It creates a ReplicaSet to bring up - 2. 运行 `kubectl get deployments` 以检查 Deployment 是否已创建。如果仍在创建 Deployment ,则输出以下内容: +2. 运行 `kubectl get deployments` 以检查 Deployment 是否已创建。如果仍在创建 Deployment ,则输出以下内容: ```shell NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE nginx-deployment 3 0 0 0 1s ``` - + 检查集群中的 Deployments 时,将显示以下字段: - - * `NAME` 列出了集群中 Deployments 的名称。 - * `DESIRED` 显示应用程序的所需 _副本_ 数,在创建 Deployment 时定义这些副本。这是 _期望状态_。 - * `CURRENT`显示当前正在运行的副本数。 - * `UP-TO-DATE`显示已更新以实现期望状态的副本数。 - * `AVAILABLE`显示应用程序可供用户使用的副本数。 - * `AGE` 显示应用程序运行的时间量。 + + * `NAME` 列出了集群中 Deployments 的名称。 + * `DESIRED` 显示应用程序的所需 _副本_ 数,在创建 Deployment 时定义这些副本。这是 _期望状态_。 + * `CURRENT`显示当前正在运行的副本数。 + * `UP-TO-DATE`显示已更新以实现期望状态的副本数。 + * `AVAILABLE`显示应用程序可供用户使用的副本数。 + * `AGE` 显示应用程序运行的时间量。 - + 请注意,根据`.spec.replicas`副本字段,所需副本的数量为 3。 - 3. 要查看 Deployment 展开状态,运行 `kubectl rollout status deployment.v1.apps/nginx-deployment`。输出: +3. 要查看 Deployment 展开状态,运行 `kubectl rollout status deployment.v1.apps/nginx-deployment`。输出: ```shell Waiting for rollout to finish: 2 out of 3 new replicas have been updated... @@ -255,36 +255,36 @@ The following is an example of a Deployment. It creates a ReplicaSet to bring up - 4. 几秒钟后再次运行 `kubectl get deployments`。输出: +4. 几秒钟后再次运行 `kubectl get deployments`。输出: ```shell NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE nginx-deployment 3 3 3 3 18s ``` - + 请注意, Deployment 已创建所有三个副本,并且所有副本都是最新的(它们包含最新的 Pod 模板)并且可用。 - 5. 要查看 Deployment 创建的 ReplicaSet (`rs`),运行 `kubectl get rs`。输出: +5. 要查看 Deployment 创建的 ReplicaSet (`rs`),运行 `kubectl get rs`。输出: ```shell NAME DESIRED CURRENT READY AGE nginx-deployment-75675f5897 3 3 3 18s ``` - + 请注意, ReplicaSet 的名称始终被格式化为`[DEPLOYMENT-NAME]-[RANDOM-STRING]`。随机字符串是随机生成并使用 pod-template-hash 作为种子。 - 6. 要查看每个 Pod 自动生成的标签,运行 `kubectl get pods --show-labels`。返回以下输出: +6. 要查看每个 Pod 自动生成的标签,运行 `kubectl get pods --show-labels`。返回以下输出: ```shell NAME READY STATUS RESTARTS AGE LABELS @@ -293,9 +293,9 @@ The following is an example of a Deployment. It creates a ReplicaSet to bring up nginx-deployment-75675f5897-qqcnn 1/1 Running 0 18s app=nginx,pod-template-hash=3123191453 ``` - + 创建的复制集可确保有三个 `nginx` Pods。 {{< note >}} @@ -350,33 +350,33 @@ is changed, for example if the labels or container images of the template are up - 1. 让我们更新 nginx Pods,以使用 `nginx:1.9.1` 镜像 ,而不是 `nginx:1.7.9` 镜像 。 +1. 让我们更新 nginx Pods,以使用 `nginx:1.9.1` 镜像 ,而不是 `nginx:1.7.9` 镜像 。 ```shell kubectl --record deployment.apps/nginx-deployment set image deployment.v1.apps/nginx-deployment nginx=nginx:1.9.1 ``` - + 输出: ```shell deployment.apps/nginx-deployment image updated ``` - + 或者,可以 `edit` Deployment 并将 `.spec.template.spec.containers[0].image` 从 `nginx:1.7.9` 更改至 `nginx:1.9.1`。 ```shell kubectl edit deployment.v1.apps/nginx-deployment ``` - + 输出: @@ -387,23 +387,23 @@ is changed, for example if the labels or container images of the template are up - 2. 要查看展开状态,运行: +2. 要查看展开状态,运行: ```shell kubectl rollout status deployment.v1.apps/nginx-deployment ``` - + 输出: ```shell Waiting for rollout to finish: 2 out of 3 new replicas have been updated... ``` - + 或者 ```shell @@ -437,9 +437,9 @@ up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas. kubectl get rs ``` - + 输出: ```shell @@ -457,10 +457,10 @@ up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas. kubectl get pods ``` - -输出: + + 输出: ```shell NAME READY STATUS RESTARTS AGE @@ -469,29 +469,29 @@ up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas. nginx-deployment-1564180365-z9gth 1/1 Running 0 14s ``` - + 下次要更新这些 Pods 时,只需再次更新 Deployment Pod 模板。 - + Deployment 可确保在更新时仅关闭一定数量的 Pods。默认情况下,它确保至少 75%所需 Pods 运行(25%最大不可用)。 - + Deployment 还确保仅创建一定数量的 Pods 高于期望的 Pods 数。默认情况下,它可确保最多增加 25% 期望 Pods 数(25%最大增量)。 - + 例如,如果仔细查看上述 Deployment ,将看到它首先创建了一个新的 Pod,然后删除了一些旧的 Pods,并创建了新的 Pods。它不会杀死老 Pods,直到有足够的数量新的 Pods 已经出现,并没有创造新的 Pods,直到足够数量的旧 Pods 被杀死。它确保至少 2 个 Pods 可用,并且总共最多 4 个 Pods 可用。 + 输出: ```shell @@ -545,14 +545,14 @@ up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas. Normal ScalingReplicaSet 14s deployment-controller Scaled down replica set nginx-deployment-2035384211 to 0 ``` - + 可以看到,当第一次创建 Deployment 时,它创建了一个 ReplicaSet (nginx-deployment-2035384211)并将其直接扩展至 3 个副本。更新 Deployment 时,它创建了一个新的 ReplicaSet (nginx-deployment-1564180365),并将其扩展为 1,然后将旧 ReplicaSet 缩小到 2,以便至少有 2 个 Pod 可用,并且最多创建 4 个 Pod。然后,它继续向上和向下扩展新的和旧的 ReplicaSet ,具有相同的滚动更新策略。最后,将有 3 个可用的副本在新的 ReplicaSet 中,旧 ReplicaSet 将缩小到 0。 + 输出: ```shell @@ -668,9 +668,9 @@ rolled back. kubectl rollout status deployment.v1.apps/nginx-deployment ``` - + 输出: ```shell @@ -694,9 +694,9 @@ rolled back. kubectl get rs ``` - + 输出: ```shell @@ -715,9 +715,9 @@ rolled back. kubectl get pods ``` - + 输出: ```shell @@ -728,14 +728,14 @@ rolled back. nginx-deployment-3066724191-08mng 0/1 ImagePullBackOff 0 6s ``` -{{< note >}} - - Deployment 控制器自动停止不良展开,并停止向上扩展新的 ReplicaSet 。这取决于指定的滚动更新参数(具体为 `maxUnavailable`)。默认情况下,Kubernetes 将值设置为 25%。 -{{< /note >}} + {{< note >}} + + Deployment 控制器自动停止不良展开,并停止向上扩展新的 ReplicaSet 。这取决于指定的滚动更新参数(具体为 `maxUnavailable`)。默认情况下,Kubernetes 将值设置为 25%。 + {{< /note >}} + 输出: ```shell @@ -790,10 +790,10 @@ rolled back. 13s 13s 1 {deployment-controller } Normal ScalingReplicaSet Scaled up replica set nginx-deployment-3066724191 to 1 ``` - - 要解决此问题,需要回滚到以前稳定的 Deployment 版本。 + + 要解决此问题,需要回滚到以前稳定的 Deployment 版本。 - 1. 首先,检查 Deployment 修改历史: +1. 首先,检查 Deployment 修改历史: ```shell kubectl rollout history deployment.v1.apps/nginx-deployment ``` - + 输出: ```shell @@ -826,16 +826,16 @@ rolled back. 3 kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.91 --record=true ``` - + `CHANGE-CAUSE` 从 Deployment 注释 `kubernetes.io/change-cause` 创建时复制到其修改版。可以通过以下条件指定 `CHANGE-CAUSE` 消息: - + * 使用 `kubectl annotate deployment.v1.apps/nginx-deployment kubernetes.io/change-cause="image updated to 1.9.1"` Deployment 对 Deployment 进行分号。 * 追加 `--record` 以保存正在更改资源的 `kubectl` 命令。 * 手动编辑资源的清单。 @@ -843,15 +843,15 @@ rolled back. - 2. 查看修改历史的详细信息,运行: +2. 查看修改历史的详细信息,运行: ```shell kubectl rollout history deployment.v1.apps/nginx-deployment --revision=2 ``` - + 输出: ```shell @@ -881,61 +881,61 @@ Follow the steps given below to rollback the Deployment from the current version - 1. 现在已决定撤消当前展开并回滚到以前的版本: +1. 现在已决定撤消当前展开并回滚到以前的版本: ```shell kubectl rollout undo deployment.v1.apps/nginx-deployment ``` - + 输出: ```shell deployment.apps/nginx-deployment ``` - + 或者,可以通过使用 `--to-revision` 来回滚到特定修改版本: ```shell kubectl rollout undo deployment.v1.apps/nginx-deployment --to-revision=2 ``` - + 输出: ```shell deployment.apps/nginx-deployment ``` - + 更多有关回滚相关指令,请参考 [`kubectl rollout`](/docs/reference/generated/kubectl/kubectl-commands#rollout). - + 现在, Deployment 将回滚到以前的稳定版本。如所见, Deployment 回滚事件回滚到修改版 2 是从 Deployment 控制器生成的。 - 2. 检查回滚是否成功、 Deployment 是否正在运行,运行: +2. 检查回滚是否成功、 Deployment 是否正在运行,运行: ```shell kubectl get deployment nginx-deployment ``` - + 输出: ```shell @@ -946,15 +946,15 @@ Follow the steps given below to rollback the Deployment from the current version - 3. 获取 Deployment 描述信息: +3. 获取 Deployment 描述信息: ```shell kubectl describe deployment nginx-deployment ``` - + 输出: ```shell @@ -1072,9 +1072,9 @@ ReplicaSets (ReplicaSets with Pods) in order to mitigate risk. This is called *p kubectl get deploy ``` - + 输出: ```shell @@ -1090,9 +1090,9 @@ ReplicaSets (ReplicaSets with Pods) in order to mitigate risk. This is called *p kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:sometag ``` - + 输出: ```shell @@ -1107,9 +1107,9 @@ ReplicaSets (ReplicaSets with Pods) in order to mitigate risk. This is called *p ```shell kubectl get rs ``` - + 输出: ```shell @@ -1190,9 +1190,9 @@ apply multiple fixes in between pausing and resuming without triggering unnecess ```shell kubectl get deploy ``` - + 输出: ```shell @@ -1200,18 +1200,17 @@ apply multiple fixes in between pausing and resuming without triggering unnecess nginx 3 3 3 3 1m ``` - + 获取 Deployment 状态: ```shell kubectl get rs ``` - - + 输出: ```shell @@ -1219,18 +1218,18 @@ apply multiple fixes in between pausing and resuming without triggering unnecess nginx-2142116321 3 3 3 1m ``` - -使用如下指令中断运行: + + 使用如下指令中断运行: ```shell kubectl rollout pause deployment.v1.apps/nginx-deployment ``` - + 输出: ```shell @@ -1246,9 +1245,9 @@ apply multiple fixes in between pausing and resuming without triggering unnecess kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.9.1 ``` - + 输出: ```shell @@ -1264,9 +1263,9 @@ apply multiple fixes in between pausing and resuming without triggering unnecess kubectl rollout history deployment.v1.apps/nginx-deployment ``` - + 输出: ```shell @@ -1284,9 +1283,9 @@ apply multiple fixes in between pausing and resuming without triggering unnecess kubectl get rs ``` - + 输出: ```shell @@ -1303,19 +1302,19 @@ apply multiple fixes in between pausing and resuming without triggering unnecess kubectl set resources deployment.v1.apps/nginx-deployment -c=nginx --limits=cpu=200m,memory=512Mi ``` - + 输出: ```shell deployment.apps/nginx-deployment resource requirements updated ``` - + 暂停 Deployment 之前的初始状态将继续其功能,但新的更新只要暂停 Deployment , Deployment 就不会产生任何效果。 + 输出: ```shell @@ -1344,9 +1343,9 @@ apply multiple fixes in between pausing and resuming without triggering unnecess kubectl get rs -w ``` - + 输出: ```shell @@ -1376,9 +1375,9 @@ apply multiple fixes in between pausing and resuming without triggering unnecess kubectl get rs ``` - + 输出: ```shell @@ -1387,198 +1386,6 @@ apply multiple fixes in between pausing and resuming without triggering unnecess nginx-3926361531 3 3 3 28s ``` - -可以在触发一个或多个更新之前暂停 Deployment ,然后继续它。这允许在暂停和恢复之间应用多个修补程序,而不会触发不必要的 Deployment 。 - - -* 例如,对于一个刚刚创建的 Deployment : - 获取 Deployment 信息: - ```shell - kubectl get deploy - ``` - - 输出: - ``` - NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE - nginx 3 3 3 3 1m - ``` - - - 获取 Deployment 状态: - ```shell - kubectl get rs - ``` - - - 输出: - ``` - NAME DESIRED CURRENT READY AGE - nginx-2142116321 3 3 3 1m - ``` - - -使用如下指令中断运行: - ```shell - kubectl rollout pause deployment.v1.apps/nginx-deployment - ``` - - - 输出: - ``` - deployment.apps/nginx-deployment paused - ``` - - -* 然后更新 Deployment 镜像: - ```shell - kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.9.1 - ``` - - - 输出: - ``` - deployment.apps/nginx-deployment image updated - ``` - - -* 注意没有新的展开: - ```shell - kubectl rollout history deployment.v1.apps/nginx-deployment - ``` - - - 输出: - ``` - deployments "nginx" - REVISION CHANGE-CAUSE - 1 - ``` - - -* 获取展开状态确保 Deployment 更新已经成功: - ```shell - kubectl get rs - ``` - - - 输出: - ``` - NAME DESIRED CURRENT READY AGE - nginx-2142116321 3 3 3 2m - ``` - - -* 更新是很容易的,例如,可以这样更新使用到的资源: - ```shell - kubectl set resources deployment.v1.apps/nginx-deployment -c=nginx --limits=cpu=200m,memory=512Mi - ``` - - - 输出: - ``` - deployment.apps/nginx-deployment resource requirements updated - ``` - - - 暂停 Deployment 之前的初始状态将继续其功能,但新的更新只要暂停 Deployment , Deployment 就不会产生任何效果。 - - -* 最后,恢复 Deployment 并观察新的 ReplicaSet ,并更新所有新的更新: - ```shell - kubectl rollout resume deployment.v1.apps/nginx-deployment - ``` - - - 输出: - ``` - deployment.apps/nginx-deployment resumed - ``` - -* 观察展开的状态,直到完成。 - ```shell - kubectl get rs -w - ``` - - - 输出: - ``` - NAME DESIRED CURRENT READY AGE - nginx-2142116321 2 2 2 2m - nginx-3926361531 2 2 0 6s - nginx-3926361531 2 2 1 18s - nginx-2142116321 1 2 2 2m - nginx-2142116321 1 2 2 2m - nginx-3926361531 3 2 1 18s - nginx-3926361531 3 2 1 18s - nginx-2142116321 1 1 1 2m - nginx-3926361531 3 3 1 18s - nginx-3926361531 3 3 2 19s - nginx-2142116321 0 1 1 2m - nginx-2142116321 0 1 1 2m - nginx-2142116321 0 0 0 2m - nginx-3926361531 3 3 3 20s - ``` - - -* 获取最近展开的状态: - ```shell - kubectl get rs - ``` - - - 输出: - ``` - NAME DESIRED CURRENT READY AGE - nginx-2142116321 0 0 0 2m - nginx-3926361531 3 3 3 28s - ``` {{< note >}}