0
0
Kubernetesdevops~10 mins

PersistentVolume (PV) definition in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - PersistentVolume (PV) definition
Write PV YAML file
kubectl apply -f pv.yaml
Kubernetes API Server receives PV spec
PV object created in cluster
PV available for claim by Pods
Pod uses PersistentVolumeClaim to bind PV
The flow shows how a PersistentVolume YAML is created, applied to the cluster, and then made available for Pods to use via claims.
Execution Sample
Kubernetes
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-example
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /mnt/data
This YAML defines a PersistentVolume named 'pv-example' with 5Gi storage and ReadWriteOnce access mode using hostPath.
Process Table
StepActionInput/CommandResult/State Change
1Write PV YAML filepv.yaml with PV specFile created with PV definition
2Apply PV to clusterkubectl apply -f pv.yamlPV object 'pv-example' created in Kubernetes
3Kubernetes API Server processes PVPV spec receivedPV stored and marked as Available
4PV ready for claimPV status AvailablePod can bind via PersistentVolumeClaim
5Pod binds PVPod PVC requests PVPV bound to Pod's PVC
💡 PV is created and available for Pods to claim and use storage.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
PV ObjectNoneCreated with specStored as AvailableReady for claimBound to Pod PVC
Key Moments - 2 Insights
Why does the PV status change to 'Available' after creation?
After applying the YAML (see execution_table step 3), Kubernetes marks the PV as 'Available' to show it is ready to be claimed by a PersistentVolumeClaim.
What happens if no Pod claims the PV?
The PV remains in 'Available' state (execution_table step 4) until a Pod's PersistentVolumeClaim binds to it or it is deleted.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the PV object created in Kubernetes?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Check the 'Result/State Change' column for when the PV object is created.
According to the variable tracker, what is the PV status after Step 3?
ANone
BStored as Available
CCreated with spec
DBound to Pod PVC
💡 Hint
Look at the 'After Step 3' column for the PV Object variable.
If the Pod never claims the PV, what will be the final state of the PV according to the execution table?
AAvailable
BDeleted
CBound to Pod PVC
DPending
💡 Hint
Refer to the key moments and execution_table step 4 about PV availability.
Concept Snapshot
PersistentVolume (PV) is a cluster resource representing storage.
Define PV in YAML with capacity, accessModes, and storage details.
Apply with 'kubectl apply -f pv.yaml' to create PV object.
PV status 'Available' means ready for claim.
Pods use PersistentVolumeClaim to bind and use PV storage.
Full Transcript
This visual execution shows how a PersistentVolume (PV) is defined and created in Kubernetes. First, a YAML file is written with the PV specification including storage size and access mode. Then, the YAML is applied using kubectl, which creates the PV object in the cluster. The Kubernetes API server processes this and marks the PV as Available, meaning it is ready to be claimed. Finally, a Pod can bind to this PV by using a PersistentVolumeClaim. The variable tracker shows the PV object's state changing from none to created, available, and finally bound. Key moments clarify why PV status changes and what happens if no Pod claims it. The quiz tests understanding of creation steps, PV status, and final states if unclaimed.