k8s.github.io

Storage Class

In this section, we will take a look at Storage Class

Static Provisioning

class-18

Dynamic Provisioning

class-19

sc-definition.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
   name: google-storage
provisioner: kubernetes.io/gce-pd

Create a Storage Class

$ kubectl create -f sc-definition.yaml
storageclass.storage.k8s.io/google-storage created

List the Storage Class

$ kubectl get sc
NAME             PROVISIONER            RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
google-storage   kubernetes.io/gce-pd   Delete          Immediate           false                  20s

Create a Persistent Volume Claim

pvc-definition.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: myclaim
spec:
  accessModes: [ "ReadWriteOnce" ]
  storageClassName: google-storage       
  resources:
   requests:
     storage: 500Mi
$ kubectl create -f pvc-definition.yaml

Create a Pod

pod-definition.yaml

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
    - name: frontend
      image: nginx
      volumeMounts:
      - mountPath: "/var/www/html"
        name: web
  volumes:
    - name: web
      persistentVolumeClaim:
        claimName: myclaim
$ kubectl create -f pod-definition.yaml

Provisioner

class-20

Kubernetes Storage Class Reference Docs