Challenge, Medium,  on  Kubernetes

Bind a PersistentVolume to a Specific Node Using Node Affinity

Scenario

Create a PersistentVolume named secure-pv with a capacity of 1Gi, using the hostPath volume type at /mnt/secure-data. Set the storageClassName to local-path, add the label app=secure-data, and configure the nodeAffinity using the key kubernetes.io/hostname so that it is available only on node-02.

Create a PersistentVolumeClaim named secure-pvc requesting 1Gi with ReadWriteOnce access mode and local-path StorageClass. Use a label selector app=secure-data and set volumeName to bind it directly to the correct PersistentVolume.

Finally, confirm that the PersistentVolumeClaim is successfully bound to the PersistentVolume.

After the PVC is bound, deploy the pod using the manifest located at:

/home/laborant/pod-bind-vol.yaml

This pod will mount the PersistentVolume and create data to verify the storage is working correctly.


# Check the data on node-02.
cat /mnt/secure-data/info.txt

Hint
  • PV: Use nodeAffinity with kubernetes.io/hostname: node-02, label app: secure-data, storageClass local-path
  • PVC: Set volumeName: secure-pv, selector.matchLabels.app: secure-data, storageClass local-path
  • Deploy: kubectl apply -f /home/laborant/pod-bind-vol.yaml
  • PersistentVolumes
  • PersistentVolumeClaims

🧪 Test Cases