Create and Inspect a Kubernetes PersistentVolume
You are working on a Kubernetes cluster where a new application requires persistent storage.
Your task is to createto create a Kubernetes PersistentVolume with the following specifications:
- Name:
devopscube-pv - Volume type:
HostPath - Host path:
/tmp/data - Storage capacity:
15Gi - Access mode:
ReadWriteMany
After creating the PersistentVolume:
- Verify that the PersistentVolume
devopscube-pvhas been created successfully. - Describe the PersistentVolume and inspect its configuration.
- Retrieve the reclaim policy of
devopscube-pvand save it to/tmp/policy.txt. - Verify that
/tmp/policy.txtcontains the reclaim policy.
Create the PersistentVolume Manifest
Create a file named devopscube-pv.yaml
The manifest should look like this:
The PersistentVolume (PV) is configured with a storage capacity of 15Gi and uses the ReadWriteMany access mode, which allows the volume to be mounted as read-write by multiple nodes, depending on the capabilities of the underlying storage. The PV uses a HostPath volume that maps the host directory /tmp/data to the volume.
Apply the Manifest
Create the PersistentVolume:
$ kubectl apply -f devopscube-pv.yaml
persistentvolume/devopscube-pv createdVerify the PersistentVolume
Check the PV:
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE
devopscube-pv 15Gi RWX Retain Available <unset> Because no PersistentVolumeClaim has been created yet, the PV should normally be in the Available state.
Describe the PersistentVolume
Describe the PV:
$ kubectl describe pv devopscube-pv
Name: devopscube-pv
Labels: <none>
Annotations: <none>
Finalizers: [kubernetes.io/pv-protection]
StorageClass:
Status: Available
Claim:
Reclaim Policy: Retain
Access Modes: RWX
VolumeMode: Filesystem
Capacity: 15Gi
Node Affinity: <none>
Message:
Source:
Type: HostPath (bare host directory volume)
Path: /tmp/data
HostPathType: The output contains information about the PV, including:
Capacity: 15Gi
Access Modes: RWX
Reclaim Policy: RetainThe exact reclaim policy may depend on the Kubernetes configuration and cluster defaults. For this task, capture the value reported by your cluster rather than assuming it.
Save the Reclaim Policy
Extract the reclaim policy from the PV description:
kubectl describe pv devopscube-pv | grep "Reclaim Policy" > /tmp/policy.txtVerify the file:
$ cat /tmp/policy.txt
Reclaim Policy: RetainThis confirms that the reclaim policy information has been saved to /tmp/policy.txt.
CKA Exam Tips
These tips will help you quickly identify the important Kubernetes concepts and avoid common mistakes during the exam.
Tip 1: Know the Access Mode Abbreviations
Kubernetes displays access modes as:
ReadWriteOnce → RWO,
ReadOnlyMany → ROX,
ReadWriteMany → RWX
For this task, use ReadWriteMany, which appears as RWX.
Tip 2: Check the HostPath
Make sure the PV uses the required path:
hostPath:
path: /tmp/data
Tip 3: Don't Assume the PV Is Bound
A new PV without a matching PVC normally has an Available status. It becomes Bound when a suitable PVC claims it.