StorageClasses

StorageClasses and Dynamic Provisioning

A StorageClass names a provisioner plus parameters, and when a claim names the class (or names none and a default class exists), the provisioner creates a matching volume. kind 14,561 's default class, standard, uses Rancher 44,355 's local-path-provisioner 2,940 (github.com/rancher/local-path-provisioner (https://github.com/rancher/local-path-provisioner 2,940 ), Apache-2.0), which creates a directory on the chosen node. The pvpod helper runs a one-shot Pod on a claim:

A claim provisioned when its first Pod is scheduledShell
kubectl apply -f - <<'EOF'
apiVersion: v1
kind: PersistentVolumeClaim
metadata: { name: notes }
spec: { accessModes: [ReadWriteOnce], resources: { requests: { storage: 100Mi } } }
EOF
pvpod() { kubectl apply -f - >/dev/null <<EOF
apiVersion: v1
kind: Pod
metadata: { name: $1 }
spec:
  restartPolicy: Never
  containers: [{ name: sh, image: "localhost:33500/booknest-web:1.3", command: [sh, -c, "$3"],
                 volumeMounts: [{ name: d, mountPath: /data }] }]
  volumes: [{ name: d, persistentVolumeClaim: { claimName: $2 } }]
EOF
kubectl wait --for=jsonpath='{.status.phase}'=Succeeded pod/$1 --timeout=90s >/dev/null
kubectl logs $1; kubectl delete pod $1 >/dev/null; }
kubectl get pvc notes -o custom-columns=$PVC
pvpod writer notes 'date +%T > /data/note; echo wrote $(cat /data/note)'
pvpod reader notes 'echo read $(cat /data/note)'
kubectl get pvc notes -o custom-columns=$PVC
PV=$(kubectl get pvc notes -o jsonpath='{.spec.volumeName}')
kubectl get pv $PV -o jsonpath='{.spec.hostPath.path}'; echo
Output
persistentvolumeclaim/notes created
NAME    STATUS    VOLUME   SIZE
notes   Pending   <none>   <none>
wrote 16:15:37
read 16:15:37
NAME    STATUS   VOLUME                                     SIZE
notes   Bound    pvc-bcf4348c-37ea-429e-93b2-9e6cab225f31   100Mi
/var/local-path-provisioner/pvc-bcf4348c-37ea-429e-93b2-9e6cab225f31_booknest_notes

The claim stayed Pending because the class uses volumeBindingMode: WaitForFirstConsumer: provisioning waits until the scheduler has placed the first Pod, so the directory is created on that node. The volume's node affinity then sent the second Pod to the same node. If the node dies, the data goes with it; cloud classes (EBS gp3, GCE persistent disks, Azure 6 disks) create network disks that can follow a Pod to another node in the zone.