How to specify a storage class to user pvc in kubeflow

9/17/2019

I am trying to attach a storage class to all the PVC request created by individual user pods for jupyter notebooks in kubeflow.

I tried editing some values and specify storage_class. but none of it is working, whenever a new pvc comes up it doesnot come with a storage class name.

The desired result is whenever a pvc of user pods comes, it should have the name of storage class attached with it. Kindly help with this. I am stuck from last day

-- Geo Antony
jupyter-notebook
kubeflow
kubernetes
persistent-storage
storage-class-specifier

2 Answers

9/17/2019

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: v1
kind: PersistentVolume
metadata:
name: task-pv-volume
labels:
type: local
spec:
storageClassName: <name_of_your_StorageClass>
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"

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

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: task-pv-claim
spec:
storageClassName: <name_of_your_StorageClass>
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi

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

apiVersion: v1
kind: Pod
metadata:
name: task-pv-pod
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
containers:
- name: task-pv-container
image: nginx
ports:
- containerPort: 80
name: "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/v1
kind: StorageClass
metadata:
  name: <name_of_your_StorageClass>
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
reclaimPolicy: Retain
allowVolumeExpansion: true
mountOptions:
  - debug
volumeBindingMode: Immediate

You can check your StorageClasses with this command:

kubectl get sc
-- jt97
Source: StackOverflow

9/17/2019

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

-- Suresh Vishnoi
Source: StackOverflow