From 5360a1917a0d040be085f9065d1dbffbe54b3575 Mon Sep 17 00:00:00 2001 From: Anirudh Ramanathan Date: Fri, 2 Dec 2016 14:52:18 -0800 Subject: [PATCH] Task: Deleting a statefulset (#1737) * Deleting a statefulset task. * Doc review fixes. --- _data/tasks.yml | 2 + docs/tasks/index.md | 1 + .../deleting-a-statefulset.md | 84 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 docs/tasks/manage-stateful-set/deleting-a-statefulset.md diff --git a/_data/tasks.yml b/_data/tasks.yml index 75c60e32e2..12c36435d6 100644 --- a/_data/tasks.yml +++ b/_data/tasks.yml @@ -39,3 +39,5 @@ toc: path: /docs/tasks/manage-stateful-set/upgrade-pet-set-to-stateful-set/ - title: Scaling a StatefulSet path: /docs/tasks/manage-stateful-set/scale-stateful-set/ + - title: Deleting a Stateful Set + path: /docs/tasks/manage-stateful-set/deleting-a-statefulset/ \ No newline at end of file diff --git a/docs/tasks/index.md b/docs/tasks/index.md index e89610777c..4796ca8b80 100644 --- a/docs/tasks/index.md +++ b/docs/tasks/index.md @@ -32,6 +32,7 @@ single thing, typically by giving a short sequence of steps. * [Upgrading from PetSets to StatefulSets](/docs/tasks/manage-stateful-set/upgrade-pet-set-to-stateful-set/) * [Scaling a StatefulSet](/docs/tasks/manage-stateful-set/scale-stateful-set/) +* [Deleting a StatefulSet](/docs/tasks/manage-stateful-set/deleting-a-statefulset/) ### What's next diff --git a/docs/tasks/manage-stateful-set/deleting-a-statefulset.md b/docs/tasks/manage-stateful-set/deleting-a-statefulset.md new file mode 100644 index 0000000000..5aa696d52d --- /dev/null +++ b/docs/tasks/manage-stateful-set/deleting-a-statefulset.md @@ -0,0 +1,84 @@ +--- +assignees: +- bprashanth +- erictune +- foxish +- janetkuo +- smarterclayton + +--- + +{% capture overview %} + +This task shows you how to delete a StatefulSet. + +{% endcapture %} + +{% capture prerequisites %} + +* This task assumes you have an application running on your cluster represented by a StatefulSet. + +{% endcapture %} + +{% capture steps %} + +### 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. + +```shell +kubectl delete -f +``` + +```shell +kubectl delete statefulsets +``` + +You may need to delete the associated headless service separately after the StatefulSet itself is deleted. + +```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`. + +```shell +kubectl delete -f --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: + +```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/user-guide/pods/index#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. + +**Note: Use caution when deleting a PVC, as it may lead to data loss.** + +#### Complete deletion of a StatefulSet + +To simply delete everything in a StatefulSet, including the associated pods, you can run a series of commands similar to the following: + +```shell +grace=$(kubectl get pods --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. + +#### Force deletion of 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/stateful-sets/deleting-pods/) for details. + +{% endcapture %} + +{% capture whatsnext %} +Learn more about debugging a StatefulSet. *TODO: Link to the task for debugging a StatefulSet* +{% endcapture %} + +{% include templates/task.md %}