How to specify a storage class to user pvc in kubeflow How to specify a storage class to user pvc in kubeflow kubernetes kubernetes

How to specify a storage class to user pvc in kubeflow


you need to have a default storage class in your cluster, so if a pvc does not specify any storage class then default one would be selected.

List the StorageClasses in your cluster:

kubectl get storageclass

Mark a StorageClass as default: set the annotation storageclass.kubernetes.io/is-default-class=true.

kubectl patch storageclass <your-class-name> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

Here are the detail steps change-default-storage-class


Basing on documentation

While PersistentVolumeClaims allow a user to consume abstract storage resources, it is common that users need PersistentVolumes with varying properties, such as performance, for different problems. Cluster administrators need to be able to offer a variety of PersistentVolumes that differ in more ways than just size and access modes, without exposing users to the details of how those volumes are implemented. For these needs there is the StorageClass resource.

A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes.

apiVersion: v1kind: PersistentVolumemetadata:name: task-pv-volumelabels:type: localspec:storageClassName: <name_of_your_StorageClass>capacity:storage: 10GiaccessModes:- ReadWriteOncehostPath:path: "/mnt/data"

A PersistentVolumeClaim (PVC) is a request for storage by a user.

apiVersion: v1kind: PersistentVolumeClaimmetadata:name: task-pv-claimspec:storageClassName: <name_of_your_StorageClass>accessModes:- ReadWriteOnceresources:requests:storage: 3Gi

Then you can create a Pod that uses your PVC as a volume(which uses PV with storageClass)

apiVersion: v1kind: Podmetadata:name: task-pv-podspec:volumes:- name: task-pv-storagepersistentVolumeClaim:claimName: task-pv-claimcontainers:- name: task-pv-containerimage: nginxports:- containerPort: 80name: "http-server"volumeMounts:- mountPath: "/usr/share/nginx/html"name: task-pv-storage

Before you are going to create a PV and PVC StorageClass must already exist, if it's not a default one will be used instead.

apiVersion: storage.k8s.io/v1kind: StorageClassmetadata:  name: <name_of_your_StorageClass>provisioner: kubernetes.io/aws-ebsparameters:  type: gp2reclaimPolicy: RetainallowVolumeExpansion: truemountOptions:  - debugvolumeBindingMode: Immediate

You can check your StorageClasses with this command:

kubectl get sc