Kubernetes – Force to Delete volumeattachments

In kubernetes it may happen that you can not get rid of a volumeattachment in deletion status. This situation is strange and should not happen but it happens. In this case can solve this undesired status as followed:

Frist list all existing volumeattachments:

$ kubectl get volumeattachment

copy the name of the volumeattachment causing the problem. Next you can try to delete it with:

$ kubectl delete volumeattachment csi-3a184154fxxxxxxxxxxxxxxxxxxxxx

Test if the volumeattachment was delete successfully.

If not, you can force the deletion by editing the volumeattachment resource itself – run:

$ kubectl edit volumeattachment csi-3a184154fxxxxxxxxxxxxxxxxxxxxx

Search for a section starting with

  - external-attacher/.....

And delete this lines so that no more ‘finalizers’ section exists. Save and close the editor (in VI this is the command ‘wq!’

Now your volumeattachment should be deleted.

If anybody knows a better solution let me know 😉

3 Replies to “Kubernetes – Force to Delete volumeattachments”

  1. Hello. I don’t understand what happen if volume attachment is deleted? Vmdk is lost? Is it possible to re attach it to a new pod?. Thanks.

  2. Hi this example just helps you to get rid of a attached volume which can block a redeployment of the pod. I run into this problem when using Longhorn. But this was a long time ago, and the current releases of Longhorn do no longer generate such situations. I do not know what you mean with ‘Vmdk’? You have PersistenceVolumes (PV) which are bound to a pod and usually can not be shared to multiple pods. So as long as a PV is attached to a ‘dying’ pod the pod blocks a redeployment. This is a feature of Kubernetes to protect your data. In any case you have to be very careful if you have sensible data.

  3. i delete the volumes but the new volume created have Attached=FALSE
    is there anything else to be done to reattach ?

Leave a Reply to Ralph Soika Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.