Merge pull request #23192 from tengqm/zh-links-tasks-2

[zh] Tidy up and fix links in tasks section (2/10)
This commit is contained in:
Kubernetes Prow Robot
2020-08-22 20:43:40 -07:00
committed by GitHub
14 changed files with 461 additions and 425 deletions
@@ -1,66 +1,76 @@
---
title: 删除 StatefulSet
content_type: task
weight: 60
---
<!--
reviewers:
- bprashanth
- erictune
- foxish
- janetkuo
- smarterclayton
title: 删除 StatefulSet
title: Delete a StatefulSet
content_type: task
weight: 60
---
-->
<!-- overview -->
<!--
This task shows you how to delete a StatefulSet.
--->
文介绍如何删除 StatefulSet。
任务展示如何删除 StatefulSet。
## {{% heading "prerequisites" %}}
<!--
* This task assumes you have an application running on your cluster represented by a StatefulSet.
--->
*假设在的集群上已经运行了由 StatefulSet 创建的应用。
*任务假设在的集群上已经运行了由 StatefulSet 创建的应用。
<!-- steps -->
## 删除 StatefulSet
## 删除 StatefulSet {#deleting-a-statefulset}
<!--
You can delete a StatefulSet in the same way you delete other resources in Kubernetes: use the `kubectl delete` command, and specify the StatefulSet either by file or by name.
--->
可以像删除 Kubernetes 中的其他资源一样删除 StatefulSet:使用 `kubectl delete` 命令,并按文件或者名字指定 StatefulSet。
可以像删除 Kubernetes 中的其他资源一样删除 StatefulSet:使用 `kubectl delete` 命令,并按文件或者名字指定 StatefulSet。
```shell
kubectl delete -f <file.yaml>
```
<!--
```shell
kubectl delete statefulsets <statefulset-name>
```
-->
```shell
kubectl delete statefulsets <statefulset 名称>
```
<!--
You may need to delete the associated headless service separately after the StatefulSet itself is deleted.
--->
删除 StatefulSet 之后,您可能需要单独删除关联的无头服务。
```shell
kubectl delete service <service-name>
```
-->
删除 StatefulSet 之后,你可能需要单独删除关联的无头服务。
```shell
kubectl delete service <服务名称>
```
<!--
Deleting a StatefulSet through kubectl will scale it down to 0, thereby deleting all pods that are a part of it.
If you want to delete just the StatefulSet and not the pods, use `--cascade=false`.
--->
通过 kubectl 删除 StatefulSet 会将其缩容为0,因此删除属于它的所有pods
如果只想删除 StatefulSet 而不删除 pods,使用 `--cascade=false`
通过 `kubectl` 删除 StatefulSet 会将其缩容为 0,因此删除属于它的所有 Pod。
如果只想删除 StatefulSet 而不删除 Pod,使用 `--cascade=false`
```shell
kubectl delete -f <file.yaml> --cascade=false
@@ -69,67 +79,72 @@ kubectl delete -f <file.yaml> --cascade=false
<!--
By passing `--cascade=false` to `kubectl delete`, the Pods managed by the StatefulSet are left behind even after the StatefulSet object itself is deleted. If the pods have a label `app=myapp`, you can then delete them as follows:
--->
通过将 `--cascade=false` 传递给 `kubectl delete`,在删除 StatefulSet 对象之后,StatefulSet 管理的 pods 会被保留下来。如果 pods 有一个标签 `app=myapp`,则可以按照如下方式删除它们:
通过将 `--cascade=false` 传递给 `kubectl delete`,在删除 StatefulSet 对象之后,
StatefulSet 管理的 Pod 会被保留下来。如果 Pod 具有标签 `app=myapp`,则可以按照
如下方式删除它们:
```shell
kubectl delete pods -l app=myapp
```
<!--
### Persistent Volumes
<!--
Deleting the Pods in a StatefulSet will not delete the associated volumes. This is to ensure that you have the chance to copy data off the volume before deleting it. Deleting the PVC after the pods have left the [terminating state](/docs/concepts/workloads/pods/pod/#termination-of-pods) might trigger deletion of the backing Persistent Volumes depending on the storage class and reclaim policy. You should never assume ability to access a volume after claim deletion.
--->
删除 StatefulSet 管理的 pods 并不会删除关联的卷。这是为了确保您有机会在删除卷之前从卷中复制数据。在pods离开[终止状态](/docs/concepts/workloads/pods/pod/#termination-of-pods)后删除 PVC 可能会触发删除支持的 Persistent Volumes,具体取决于存储类和回收策略。声明删除后,您永远不应该假设能够访问卷。
-->
### 持久卷 {#persistent-volumes}
删除 StatefulSet 管理的 Pod 并不会删除关联的卷。这是为了确保你有机会在删除卷之前从卷中复制数据。
在 Pod 离开[终止状态](/zh/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination)
后删除 PVC 可能会触发删除背后的 PV 持久卷,具体取决于存储类和回收策略。
永远不要假定在 PVC 删除后仍然能够访问卷。
<!--
**Note: Use caution when deleting a PVC, as it may lead to data loss.**
--->
**注意:删除 PVC 时要谨慎,因为这可能会导致数据丢失。**
Use caution when deleting a PVC, as it may lead to data loss.
-->
{{< note >}}
删除 PVC 时要谨慎,因为这可能会导致数据丢失。
{{< /note >}}
<!--
### Complete deletion of a StatefulSet
--->
### 完全删除 StatefulSet
<!--
To simply delete everything in a StatefulSet, including the associated pods, you can run a series of commands similar to the following:
--->
要简单地删除 StatefulSet 中的所有内容,包括关联的 pods,您可能需要运行一系列类似于以下内容的命令:
-->
### 完全删除 StatefulSet {#complete-deletion-of-a-statefulset}
要简单地删除 StatefulSet 中的所有内容,包括关联的 pods,你可能需要运行一系列类似于以下内容的命令:
```shell
grace=$(kubectl get pods <stateful-set-pod> --template '{{.spec.terminationGracePeriodSeconds}}')
kubectl delete statefulset -l app=myapp
sleep $grace
kubectl delete pvc -l app=myapp
```
<!--
In the example above, the Pods have the label `app=myapp`; substitute your own label as appropriate.
--->
在上面的例子中,pods 的标签为 `app=myapp`;适当地替换自己的标签。
-->
在上面的例子中,Pod 的标签为 `app=myapp`;适当地替换自己的标签。
<!--
### Force deletion of StatefulSet pods
--->
### 强制删除 StatefulSet 类型的 pods
<!--
If you find that some pods in your StatefulSet are stuck in the 'Terminating' or 'Unknown' states for an extended period of time, you may need to manually intervene to forcefully delete the pods from the apiserver. This is a potentially dangerous task. Refer to [Deleting StatefulSet Pods](/docs/tasks/manage-stateful-set/delete-pods/) for details.
--->
如果您发现 StatefulSet 中的某些 pods 长时间处于 'Terminating' 或者 'Unknown' 状态,则可能需要手动干预以强制从 apiserver 中删除 pods。这是一项潜在的危险任务。详细信息请阅读[删除 StatefulSet 类型的 Pods](/docs/tasks/manage-stateful-set/delete-pods/)。
-->
### 强制删除 StatefulSet 的 Pod
如果你发现 StatefulSet 的某些 Pod 长时间处于 'Terminating' 或者 'Unknown' 状态,
则可能需要手动干预以强制从 API 服务器中删除这些 Pod。
这是一项有点危险的任务。详细信息请阅读
[删除 StatefulSet 类型的 Pods](/zh/docs/tasks/run-application/delete-stateful-set/)。
## {{% heading "whatsnext" %}}
<!--
Learn more about [force deleting StatefulSet Pods](/docs/tasks/run-application/force-delete-stateful-set-pod/).
--->
了解更多有关[强制删除 StatefulSet 类型的 Pods](/docs/tasks/run-application/force-delete-stateful-set-pod/)。
进一步了解[强制删除 StatefulSet 的 Pods](/zh/docs/tasks/run-application/force-delete-stateful-set-pod/)。
@@ -1,92 +1,167 @@
---
approvers:
- bprashanth
- enisoc
- erictune
- foxish
- janetkuo
- kow3ns
- smarterclayton
title: 弹缩StatefulSet
title: 扩缩 StatefulSet
content_type: task
---
<!-- overview -->
本文介绍如何弹缩StatefulSet.
<!--
This task shows how to scale a StatefulSet. Scaling a StatefulSet refers to increasing or decreasing the number of replicas.
-->
本文介绍如何扩缩StatefulSet。StatefulSet 的扩缩指的是增加或者减少副本个数。
## {{% heading "prerequisites" %}}
<!--
* StatefulSets are only available in Kubernetes version 1.5 or later.
To check your version of Kubernetes, run `kubectl version`.
* StatefulSets仅适用于Kubernetes1.5及以上版本.
* **不是所有Stateful应用都适合弹缩.** 在弹缩前您的应用前. 您必须充分了解您的应用, 不适当的弹缩StatefulSet或许会造成应用自身功能的不稳定.
* 仅当您确定该Stateful应用的集群是完全健康才可执行弹缩操作.
* Not all stateful applications scale nicely. If you are unsure about whether to scale your StatefulSets, see [StatefulSet concepts](/docs/concepts/workloads/controllers/statefulset/) or [StatefulSet tutorial](/docs/tutorials/stateful-application/basic-stateful-set/) for further information.
* You should perform scaling only when you are confident that your stateful application
cluster is completely healthy.
-->
* StatefulSets 仅适用于 Kubernetes 1.5 及以上版本。
* 不是所有 Stateful 应用都能很好地执行扩缩操作。
如果你不是很确定是否要扩缩你的 StatefulSet,可先参阅
[StatefulSet 概念](/zh/docs/concepts/workloads/controllers/statefulset/)
或者 [StatefulSet 教程](/zh/docs/tutorials/stateful-application/basic-stateful-set/)。
* 仅当你确定你的有状态应用的集群是完全健康的,才可执行扩缩操作.
<!-- steps -->
## 使用 `kubectl` 弹缩StatefulSets
<!--
## Scaling StatefulSets
弹缩请确认 `kubectl` 已经升级到Kubernetes1.5及以上版本. 如果不确定, 执行 `kubectl version` 命令并检查使用的 `Client Version`.
### Use kubectl to scale StatefulSets
### `kubectl 弹缩`
首先, 找到您想要弹缩的StatefulSet. 记住, 您需先清楚是否能弹缩该应用.
First, find the StatefulSet you want to scale.
```shell
kubectl get statefulsets <stateful-set-name>
```
-->
## 扩缩 StatefulSet {#scaling-statefulset}
改变StatefulSet副本数量:
## 使用 `kubectl` 扩缩 StatefulSet
首先,找到你要扩缩的 StatefulSet。
```shell
kubectl get statefulsets <statefulset 名称>
```
<!--
Change the number of replicas of your StatefulSet:
```shell
kubectl scale statefulsets <stateful-set-name> --replicas=<new-replicas>
```
-->
更改 StatefulSet 中副本个数:
### 可使用其他命令: `kubectl apply` / `kubectl edit` / `kubectl patch`
```shell
kubectl scale statefulsets <statefulset 名称> --replicas=<新的副本数>
```
另外, 您可以 [in-place updates](/docs/concepts/cluster-administration/manage-deployment/#in-place-updates-of-resources) StatefulSets.
<!--
### Make in-place updates on your StatefulSets
如果您的StatefulSet开始由 `kubectl apply``kubectl create --save-config` 创建,更新StatefulSet manifests中的 `.spec.replicas`, 然后执行命令 `kubectl apply`:
Alternatively, you can do [in-place updates](/docs/concepts/cluster-administration/manage-deployment/#in-place-updates-of-resources) on your StatefulSets.
If your StatefulSet was initially created with `kubectl apply`,
update `.spec.replicas` of the StatefulSet manifests, and then do a `kubectl apply`:
-->
### 对 StatefulSet 执行就地更新
另外, 你可以[就地更新](/zh/docs/concepts/cluster-administration/manage-deployment/#in-place-updates-of-resources) StatefulSet。
如果你的 StatefulSet 最初通过 `kubectl apply``kubectl create --save-config` 创建,
你可以更新 StatefulSet 清单中的 `.spec.replicas`, 然后执行命令 `kubectl apply`:
<!--
```shell
kubectl apply -f <stateful-set-file-updated>
```
除此之外, 可以通过命令 `kubectl edit` 编辑该字段:
Otherwise, edit that field with `kubectl edit`:
```shell
kubectl edit statefulsets <stateful-set-name>
```
或使用 `kubectl patch`:
Or use `kubectl patch`:
```shell
kubectl patch statefulsets <stateful-set-name> -p '{"spec":{"replicas":<new-replicas>}}'
```
-->
```shell
kubectl apply -f <更新后的 statefulset 文件>
```
## 排查故障
否则,可以使用 `kubectl edit` 编辑副本字段:
### 缩容工作不正常
```shell
kubectl edit statefulsets <statefulset 名称>
```
当Stateful管理下的任何一个Pod不健康时您不能缩容该StatefulSet. 仅当Stateful下的所有Pods都处于运行和ready状态后才可缩容.
或者使用 `kubectl patch`
当一个StatefulSet的size > 1, 如果有一个Pod不健康, 没有办法让Kubernetes知道是否是由于永久性故障还是瞬态(升级/维护/节点重启)导致. 如果该Pod不健康是由于永久性
故障导致, 则在不纠正该故障的情况下进行缩容可能会导致一种状态, 即StatefulSet下的Pod数量低于应正常运行的副本数. 这也许会导致StatefulSet不可用.
```shell
kubectl patch statefulsets <statefulset 名称> -p '{"spec":{"replicas":<new-replicas>}}'
```
如果由于瞬态故障而导致Pod不健康,并且Pod可能再次可用,那么瞬态错误可能会干扰您对
StatefulSet的扩容/缩容操作. 一些分布式数据库在节点加入和同时离开时存在问题. 在
这些情况下,最好是在应用级别进行弹缩操作, 并且只有在您确保Stateful应用的集群是完全健康时才执行弹缩.
<!--
## Troubleshooting
### Scaling down does not work right
-->
## 故障排查 {#troubleshooting}
### 缩容操作无法正常工作
<!--
You cannot scale down a StatefulSet when any of the stateful Pods it manages is unhealthy. Scaling down only takes place
after those stateful Pods become running and ready.
If spec.replicas > 1, Kubernetes cannot determine the reason for an unhealthy Pod. It might be the result of a permanent fault or of a transient fault. A transient fault can be caused by a restart required by upgrading or maintenance.
-->
当 Stateful 所管理的任何 Pod 不健康时,你不能对该 StatefulSet 执行缩容操作。
仅当 StatefulSet 的所有 Pod 都处于运行状态和 Ready 状况后才可缩容.
如果 `spec.replicas` 大于 1Kubernetes 无法判定 Pod 不健康的原因。
Pod 不健康可能是由于永久性故障造成也可能是瞬态故障。
瞬态故障可能是节点升级或维护而引起的节点重启造成的。
<!--
If the Pod is unhealthy due to a permanent fault, scaling
without correcting the fault may lead to a state where the StatefulSet membership
drops below a certain minimum number of replicas that are needed to function
correctly. This may cause your StatefulSet to become unavailable.
-->
如果该 Pod 不健康是由于永久性故障导致, 则在不纠正该故障的情况下进行缩容可能会导致
StatefulSet 进入一种状态,其成员 Pod 数量低于应正常运行的副本数。
这种状态也许会导致 StatefulSet 不可用。
<!--
If the Pod is unhealthy due to a transient fault and the Pod might become available again,
the transient error may interfere with your scale-up or scale-down operation. Some distributed
databases have issues when nodes join and leave at the same time. It is better
to reason about scaling operations at the application level in these cases, and
perform scaling only when you are sure that your stateful application cluster is
completely healthy.
-->
如果由于瞬态故障而导致 Pod 不健康并且 Pod 可能再次变为可用,那么瞬态错误可能会干扰
你对 StatefulSet 的扩容/缩容操作。 一些分布式数据库在同时有节点加入和离开时
会遇到问题。在这些情况下,最好是在应用级别进行分析扩缩操作的状态, 并且只有在确保
Stateful 应用的集群是完全健康时才执行扩缩操作。
## {{% heading "whatsnext" %}}
了解更多 [deleting a StatefulSet](/docs/tasks/manage-stateful-set/deleting-a-statefulset/).
<!--
* Learn more about [deleting a StatefulSet](/docs/tasks/run-application/delete-stateful-set/).
-->
* 进一步了解[删除 StatefulSet](/zh/docs/tasks/run-application/delete-stateful-set/)