PersistentVolumes represent storage capacity, PersistentVolumeClaims request it, and StorageClasses define dynamic provisioning behavior. This lab uses a hostPath PV only to make the binding lifecycle visible on a single-node lab.
1. Prepare and execute
Confirm the active kubeconfig context and namespace before applying changes. Save commands and manifests in version control without credentials.
kubectl create namespace storage-lab
sudo install -d -m 0777 /srv/k8s/pv-demo
kubectl get storageclass
2. Declarative configuration
Save the following example in a clearly named YAML file, review it, then use server-side dry-run when the API is available.
apiVersion: v1
kind: PersistentVolume
metadata: {name: pv-demo}
spec:
capacity: {storage: 1Gi}
accessModes: [ReadWriteOnce]
persistentVolumeReclaimPolicy: Retain
storageClassName: manual
hostPath: {path: /srv/k8s/pv-demo}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata: {name: data, namespace: storage-lab}
spec:
accessModes: [ReadWriteOnce]
storageClassName: manual
resources: {requests: {storage: 512Mi}}
3. Verify the result
A successful command is not enough. Inspect resource state, conditions, events, endpoints, logs, and an end-to-end request where applicable.
kubectl apply -f storage.yaml
kubectl get pv
kubectl -n storage-lab get pvc
kubectl describe pv pv-demo
kubectl -n storage-lab describe pvc data
4. Troubleshooting
A Pending PVC means no compatible PV or provisioner matched class, access mode, capacity, topology, or selector. hostPath is node-local and unsuitable for multi-node production data.
5. Rollback and cleanup
Review the exact target before deleting resources, especially namespaces, claims, Secrets, and cluster-wide add-ons.
kubectl -n storage-lab delete pvc data
kubectl get pv pv-demo
kubectl delete pv pv-demo
sudo rm -rf /srv/k8s/pv-demo
Production checklist
- The active context, namespace, and target version were verified.
- Manifests passed client or server-side validation.
- Resource conditions and recent events show no unresolved error.
- Access, network exposure, resource limits, persistence, and rollback were reviewed.
- Commands and expected output were recorded for the operating team.
References: topic documentation and Kubernetes documentation.