Inspect available storage classes
kubectl get storageclass
kubectl -n gnu-k8s-fundamentals get pvc
kubectl get pv- StorageClass and PV are cluster-scoped.
- PVC is namespaced.
Move application data out of ephemeral container filesystems and understand the claim/provision/bind lifecycle used by Kubernetes storage.
A PersistentVolumeClaim is a namespaced request for storage. A PersistentVolume represents storage capacity made available to the cluster. Binding matches a claim to suitable volume capacity/access characteristics.
A StorageClass describes a storage class/provisioner and parameters. When dynamic provisioning is available, creating a PVC can cause a matching PV to be provisioned automatically instead of an administrator creating it first.
Deleting a Pod does not necessarily delete the PVC/PV. The reclaim behavior is governed by storage objects and policy, not by the container filesystem lifecycle.
kubectl get storageclass
kubectl -n gnu-k8s-fundamentals get pvc
kubectl get pvGoal: Create a dynamically provisioned PVC, write data from one Pod, replace the Pod and read the same data.
cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: course-data
namespace: gnu-k8s-fundamentals
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 100Mi
EOFcat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: storage-writer
namespace: gnu-k8s-fundamentals
spec:
containers:
- name: app
image: busybox:1.36
command: ["sh","-c","echo persistent-kubernetes > /data/value; sleep 3600"]
volumeMounts: [{name: data, mountPath: /data}]
volumes:
- name: data
persistentVolumeClaim: {claimName: course-data}
EOF
kubectl -n gnu-k8s-fundamentals wait --for=condition=Ready pod/storage-writer --timeout=120skubectl -n gnu-k8s-fundamentals delete pod storage-writer --wait=truecat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: storage-reader
namespace: gnu-k8s-fundamentals
spec:
restartPolicy: Never
containers:
- name: app
image: busybox:1.36
command: ["cat","/data/value"]
volumeMounts: [{name: data, mountPath: /data}]
volumes:
- name: data
persistentVolumeClaim: {claimName: course-data}
EOF
kubectl -n gnu-k8s-fundamentals wait --for=jsonpath='{.status.phase}'=Succeeded pod/storage-reader --timeout=120s
kubectl -n gnu-k8s-fundamentals logs storage-readerkubectl -n gnu-k8s-fundamentals delete pod storage-reader
kubectl -n gnu-k8s-fundamentals delete pvc course-dataDatabases, queues and stateful applications require storage lifecycles that are independent of individual Pods.
Open each answer only after you have tried to answer the question yourself.
PersistentVolumeClaim.
Dynamic provisioning of PersistentVolumes through its configured provisioner.
To prove data lifetime is independent of that Pod instance.