Score:0

Kubernetes - PersitentVolume vs StorageClass

de flag

I have this example of a Persitent Volume from this article on postgresql via kubernetes statefulset

kind: PersistentVolume
apiVersion: v1
metadata:
  name: pgdata
  labels:
    app: postgres
    type: local
spec:
  storageClassName: sc001
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/var/data"

This seems to works but have trouble with the logic.

  1. as far as I understand the matter you need either a persistentVolume or a storageClass to fulfill the needs of a PersistentVolumeClaim. Where a PV is static while SC is dynamic. I understand either/or as exclusive either one or the other, not both (I believe that is called NOR in oposition to OR).
    So I do not understand what a storageClaseName is doing in here. Can anybody help me out with the logical understanding?

  2. I believe type: local & path: "/var/data" mean that the the volume exists in the local filesystem of the node and it's content could be found in the /var/data directory on that node
    What value would I have to use for type whether I wanted to use something else? like storage provided by a provisioner (csi.vsphere.vmware.com in my case)?

Score:3
us flag

Hope I got the question right.

A persistentVolumeClaim always binds to a persistentVolume, the idea is to have a claim connected to a disk that way the pod can attach to the same disk regardless to which node it deploys on.

A storageClass is an automatic persistentVolume provisioning mechanism, meaning if you specify a persistentVolumeClaim and there is a default storageClass configured, it will create a persistentVolume and attach it to the persistentVolumeClaim.

You can also manually create a persistentVolume and it will attach to the persistentVolumeClaim (regardless to a storageClass), but image a big environment with hundreds of pvcs and maintaining a pv to each pvc.

You can also specify a pv to attach the pvc to.

The type:local configuration is a local volume on the node which acts as a pv. In your case, vmware creates a vmdk file and copies it to the node on which the pod is deployed on.

Hope that helps.

vrms avatar
de flag
thx for your comment. So my understanding `PV` **or** `sc` is incorrect then? There is always a `pv` just the way the actual storage in the background ist being provided for that is different (either manual or via a sc).
vrms avatar
de flag
Maybe the term of _"manual creation of a persistent Volume"_ is what misleads me. Does that mean `kubctl create pv ...` (or the equivalent .yaml file) or manually creating i.e a vmdk disk on a node (or elsewhere) which can be used to provision actual physocal storage for such a pv object?
Score:0
br flag
Question: So I do not understand what a storageClaseName is doing in here. Can anybody help me out with the logical understanding?

The storageClaseName is to specify, the class of a persistent volume. I will make use of a use case to explain. Imagine you want to manage the storage of your production critical apps in 3 different categories. Gold, Silver and Bronze. Gold is for production grade critical applications and rest are for less critical apps. Now you can easily assign what type of storage you want to assign for an application based on its risk level. For example I want to use Gold class storage for my video-streaming service, then I will have to specify a PVC with a storageClassName set to gold class. Now kubernetes will find(if available) a PV which belongs to gold class category to satisfy this request. If there exists a PV which is by size sufficient for this PVC, but doesn't not belong to Gold class then that PV will not be used to satisfy this requirement.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: gold-class-claim
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: gold-class-storage
  ....
Question: What value would I have to use for type whether I wanted to use something else?

Please refer to this link: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#types-of-persistent-volumes

vrms avatar
de flag
do you mean the `type` is always one of the types listed on that link (so in my case (vmware tanzu cluster) most likely `vsphereVolume`)?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.