Delete a StatefulSet

    • This task assumes you have an application running on your cluster represented by a StatefulSet.

    You can delete a StatefulSet in the same way you delete other resources in Kubernetes: use the command, and specify the StatefulSet either by file or by name.

      You may need to delete the associated headless service separately after the StatefulSet itself is deleted.

      By passing --cascade=orphan 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:

      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 terminated 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.

      To delete everything in a StatefulSet, including the associated pods, you can run a series of commands similar to the following:

      1. kubectl delete statefulset -l app=myapp
      2. kubectl delete pvc -l app=myapp

      In the example above, the Pods have the label ; substitute your own label as appropriate.

      Learn more about force deleting StatefulSet Pods.