Kubectl Delete PVC

This article will show you how to build and maintain a Persistent Volume Claim (PVC). We will go over the definitions of persistent volume and persistent volume claim in depth. We will also show how to set up a PersistentVolumeClaim for storage in a Pod. We will go through each step in detail, from making a persistent volume claim to deleting it. So, let’s get this discussion started.

What is PersistentVolume (PV) and PersistentVolumeClaim (PVC)?

A PersistentVolume (PV) is defined as a storage chunk that has been manually created or dynamically provisioned via Storage Classes in a cluster. It functions as a cluster resource in the same way a node does. PVs are volume plugins similar to Volumes, but their lifecycle is independent of the Pods. This API object tracks the storage method, whether NFS, iSCSI or a storage system native to a cloud provider.

A PersistentVolumeClaim is a user’s request for storage (PVC). It appears to be a Pod. Pods consume node resources, whereas PVCs consume PV resources. Pods have the ability to request resource levels that are specific to them (CPU and Memory).

In claims, specific size and access modalities may be required (e.g., they can be mounted ReadOnlyMany, ReadWriteOnce, ReadWriteMany, or see AccessModes).

While PersistentVolumeClaims enable users to consume abstract storage resources, it is typical for users to require PersistentVolumes with distinct features, such as performance, for various situations.

Without exposing users to technical details, cluster managers must offer a selection of PersistentVolumes that vary in more aspects than just size and access mode. The StorageClass resource can be used to meet these requirements.


To get started, you will need a Kubernetes cluster and the kubectl command-line tool configured to connect with it. Minikube can help you set up a cluster if you don’t already have one. Ubuntu 20.04 was used to implement the commands in this topic. We can also utilize our preferred operating system since we already have kubectl installed. It must be installed before the commands can be run.

When the installation is done, we can start a terminal by using either of the two methods. One option is to use our operating system’s application bar to reach the terminal. Another way is to use the keyboard shortcut “Ctrl + Alt + T.” To start a terminal, select one of these options.

Now, at the terminal, use the command below to start the Minikube.

$ minikube start

The output is attached in the above-affixed image.

Steps for Creating an Html File on Your Node

To create an Html file, you will need to open a shell on the cluster’s sole Node. The way you open a shell is determined by how your cluster is configured. If you’re using Minikube, typing minikube ssh will open a shell on your Node. Create a /mnt/data directory in your Node’s shell.

Make an index.html file. The file is created in the /mnt/data directory. If your Node demands superuser access via a tool other than sudo, you can usually have this function by substituting sudo with the name of the alternative tool.

$ sudo sh -c "echo 'Hello from Kubernetes storage' > /mnt/data/index.html"

Make sure the index.html file is present. Also included is the output. You can now shut off the shell that is attached to your Node.

$ cat /mnt/data/index.html

The output is attached in the above-affixed image.

Steps for Creating a Persistentvolume

Here you can find out the details on creating a hostPath PersistentVolume. On a single-node cluster, Kubernetes enables hostPath for development and testing. A hostPath PersistentVolume uses a file or directory on the Node to imitate network-attached storage.

$ nano pvc.yaml

You wouldn’t be able to use hostPath in a production cluster. Cluster administrators can also use StorageClasses to build up dynamic provisioning. The hostPath PersistentVolume configuration file is as follows:

The PV configuration will differ significantly depending on your cluster and storage type. The command above will mount the volume on the minikube VM and is compatible with minikube clusters.

According to the configuration file, the disc is stored at the location of /mnt/data on the cluster’s Node. The volume’s size is set to 10 gibibytes, and the access mode is set to ReadWriteOnce, indicating that the volume can always be mounted read-write by a particular Node.

To build a PersistentVolume, use the succeeding command:

$ kubectl apply –f pvc.yaml

The output is attached in the above-affixed image. Keep in mind that the abbreviation pvc can be used to search for persistent volume claims. The output includes the name of the PVC that was produced as well as some basic information:

The output is attached in the above-affixed image.

Delete the PersistentVolume

The kubectl delete command can be used to delete PVCs. To delete a PVC with kubectl, provide it by file or name.

$ kubectl delete pv task-pv-volume

The output is attached in the above-affixed image. Please keep in mind that deleting a pv or pvc that is currently in use by a pod does not remove the PVC immediately. PVC cleanup will be postponed until all pods have stopped using it.

Furthermore, in a time when an administrator deletes a PV that is attached to a PVC, the PV is not deleted on the spot. The PV is not disconnected from the PVC until it is no longer connected.


To summarize, storage classes in Kubernetes enable the deployment and consumption of Persistent Volumes storage resources (PV). PVs are consumed by pods using PVC. This article explained how to create and delete a PersistentVolumeClaim for Pod storage. We have also provided sections on how you can deal with persistent volume claims (Pvc).

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content