Lab 09 · PVC stuck in Pending
Goal
Two PVCs are Pending. Tell a real problem apart from expected behavior, and fix the real one.
Setup
Use the kind cluster from Build a Lab Cluster on Your Laptop. kind ships one StorageClass, standard, backed by the local-path provisioner.
kubectl apply -f - <<'EOF'
apiVersion: v1
kind: Namespace
metadata:
name: lab-09
---
# Case A: a claim and the Pod that needs it
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data
namespace: lab-09
spec:
storageClassName: fast-ssd
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: app
namespace: lab-09
spec:
containers:
- name: nginx
image: nginx:1.29.3-alpine
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: data
---
# Case B: a claim nobody uses yet
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cache
namespace: lab-09
spec:
storageClassName: standard
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
EOF
Symptoms
kubectl -n lab-09 get pvc # data and cache are both Pending
kubectl -n lab-09 get pods # app is Pending
Both claims look the same in the list. They are not the same problem.
Investigate
kubectl -n lab-09 describe pvc data # read Events at the bottom
kubectl -n lab-09 describe pvc cache
kubectl -n lab-09 describe pod app
kubectl get storageclass
kubectl get storageclass standard -o jsonpath='{.provisioner} {.volumeBindingMode}{"\n"}'
Hints
Hint 1
The list only says Pending. The reason is in the events of each PVC. Compare them: one is a Warning, one is a Normal event.
Hint 2
Compare the storageClassName of each claim with kubectl get storageclass. A claim can only be provisioned by a class that exists.
Hint 3
Look at volumeBindingMode of standard. With WaitForFirstConsumer, the volume is created only after a Pod that uses the claim is scheduled, so the volume lands on the same node as the Pod.
Solution
Solution
Case A, data: a real problem. Its events show a ProvisioningFailed warning saying that storage class fast-ssd is not found. No class means no provisioner, so the claim waits forever, and the Pod app waits with it.
storageClassName cannot be changed on an existing claim, so delete and recreate. Use standard, or leave the field out to get the default class.
kubectl -n lab-09 delete pod app
kubectl -n lab-09 delete pvc data
kubectl apply -f - <<'EOF'
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data
namespace: lab-09
spec:
storageClassName: standard
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: app
namespace: lab-09
spec:
containers:
- name: nginx
image: nginx:1.29.3-alpine
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: data
EOF
On a real cluster the other fix is to create the fast-ssd StorageClass the app expects, if the team really wants that class.
Case B, cache: not a problem. Its event is a Normal WaitForFirstConsumer event: waiting for first consumer to be created before binding. standard uses WaitForFirstConsumer, so nothing is provisioned until a Pod uses the claim. Do nothing, or start a Pod that uses it and watch it bind:
kubectl apply -f - <<'EOF'
apiVersion: v1
kind: Pod
metadata:
name: cache-user
namespace: lab-09
spec:
containers:
- name: nginx
image: nginx:1.29.3-alpine
volumeMounts:
- name: cache
mountPath: /cache
volumes:
- name: cache
persistentVolumeClaim:
claimName: cache
EOF
Verify
kubectl -n lab-09 get pvc # data and cache are Bound
kubectl -n lab-09 get pods # app and cache-user are Running
kubectl get pv # one PV per claim, made by the provisioner
Clean up
kubectl delete namespace lab-09
The local-path PVs use the Delete reclaim policy, so they go away with their claims.