Kubernetes: StorageClass with local provisioner and StatefulSet kind

5/12/2020

One of my pods has 'StatefulSet' kind with volumeClaimTemplates section referring to a StorageClass(SC) I created, see below.

SC:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

StatefulSet YAML with reference to above created SC:

volumeClaimTemplates:
    - metadata:
        name: mydata
      spec:
        storageClassName: local-storage
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 2Gi

As far as I am aware, a StatefulSet will create node specific PVCs without a need for explicit PV and PVC set up, I see that PV being created but the pod status is 'pending' with below warning.

Warning FailedScheduling default-scheduler 0/4 nodes are available: 4 node(s) didn't find available persistent volumes to bind.

Note that I don't have a default StorageClass set up in the cluster, I believe that's not required for this scenario, is that correct? Do we need to enable or configure anything for 'local' provisioner to work in the cluster?

Thanks

-- cnu
kubernetes
kubernetes-statefulset
persistent-volume-claims

2 Answers

5/12/2020

From what I understand you need to go over this document for configuring the local volume static provisioner.

I would also suggest going over the user guide as there might be other steps needed to get this to properly work.

-- omricoco
Source: StackOverflow

5/13/2020

Found out hard way that missing piece for this to work was PV set up.

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-loc-sc
spec:
  persistentVolumeReclaimPolicy: Delete
  storageClassName: local-storage 
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  local:
    path: "/var/lib/test"
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - my-test-node-host-name

The FailedScheduling warning went away with PV, SC, and reference to the SC in StatefulSet pod YAML.

-- cnu
Source: StackOverflow