delete PersistentVolumeClaim in Kubernetes cluster

10/25/2018

I have a PersistentVolumeClaim in Kubernetes cluster. I would like to delete and recreate it, in my development environment to, in this way, sort of reset some services that use it.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: kafka-disk1
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: managed-premium
  resources:
    requests:
      storage: 1Gi

What is the best way to accomplish this?

Sorry for this noob question!

-- Greg Balajewicz
azure-kubernetes
kubernetes

1 Answer

10/25/2018
  • the imperative way:

    $ kubectl delete pvc kafka-disk1

  • the declarative way:

    you can label your resources , and then do kubectl apply -f with prune option , and label , so when you delete the yaml from the manifest directory , kubectl will contact the api server and compare the resources on the file and in the cluster , and the missing resource in the files will be deleted

-- Ijaz Ahmad Khan
Source: StackOverflow