Skip to main content
In this walkthrough you’ll persist application logs for a running Pod using a node hostPath and then migrate that storage to a Kubernetes PersistentVolume (PV) and PersistentVolumeClaim (PVC). Steps include inspecting the Pod and logs, adding a hostPath volume, creating a PV and PVC, resolving an accessMode mismatch, switching the Pod to use the PVC, and understanding reclaim policies and PVC termination behavior. Table of contents
  • Inspect the Pod and view logs
  • Add a hostPath volume to persist logs on the host
  • Create a PersistentVolume (PV)
  • Create a PersistentVolumeClaim (PVC)
  • Resolve accessMode mismatch and bind PVC to PV
  • Update the Pod to use the PVC
  • Reclaim policy and PVC deletion behavior
  • Links and references

Inspect the Pod and view logs

First confirm the Pod is Running:
Example output:
The application in this example writes logs to /log/app.log inside the container. View the file directly from the Pod:
Sample log output:
Inspect the Pod to see configured volumes and mounts:
Relevant excerpt (volume section):
There are no application volumes configured—only the default kube-api-access. Because logs live inside the container filesystem, deleting the Pod will delete the logs.
hostPath persists data only on the node where the Pod runs. In multi-node clusters a hostPath is tied to that specific node and is not portable; prefer network-backed storage (NFS, cloud volumes, CSI drivers) for production workloads.

Add a hostPath volume to persist logs on the host

To persist logs on the node, add a hostPath volume to the Pod spec and mount it to the container path where the application writes logs (/log). Pod YAML fragment (container + volumeMount):
Because Pods are immutable for many fields, recreate the Pod to apply the change:
After the Pod restarts, logs written to /log/app.log inside the container are persisted on the host at /var/log/webapp/app.log:
Sample output:

Create a PersistentVolume (PV)

Next create a PersistentVolume to back storage. For demo purposes this PV uses hostPath, but in production use a network or cloud-backed storage class. pv.yaml
Create and verify the PV:
Example output:

Create a PersistentVolumeClaim (PVC)

Create a PVC that requests storage for application logs. This example intentionally starts with an accessMode mismatch to illustrate binding behavior. Initial pvc.yaml:
Create the PVC and check status:
You may see the PVC in Pending state because the PV’s accessModes (RWX) do not match the PVC’s accessModes (RWO). Kubernetes only binds PVs to PVCs when capacity, access modes, and selectors match.

Resolve accessMode mismatch and bind PVC to PV

To bind the PVC to the PV, update the PVC to request ReadWriteMany (RWX) to match the PV. Some Pod/PVC fields cannot be modified in place, so we replace the PVC after editing. Updated pvc.yaml:
Replace the PVC:
Check binding status:
Example output:
Observe that once bound the PVC reports the PV’s capacity (100Mi) and access modes.

Update the Pod to use the PVC

Replace the previous hostPath volume in the Pod with a persistentVolumeClaim volume that references claim-log-1. Pod YAML fragment using the claim:
Recreate or replace the Pod to apply the volume change:
Now the container’s /log/app.log is backed by the PV/PVC and the underlying host path /pv/log (from the PV) will contain the log file:
Sample content:

Reclaim policy and PVC deletion behavior

Check the PV’s reclaim policy:
You should see:
With Retain, deleting the PVC does not remove the underlying storage — the PV moves to Released and the data remains in place. An administrator must manually clean or recycle the storage before the PV can be reused. If you attempt to delete a PVC that is still in use by a Pod, PVC deletion can hang in Terminating because of the kubernetes.io/pvc-protection finalizer, which prevents accidental data loss. Example of a stuck PVC:
You may see:
Describe the PVC to see the finalizer and the Pod that is using it:
Relevant excerpt:
Because the PVC is still in use by the webapp Pod, the finalizer prevents deletion. Delete the Pod first, then the PVC deletion will complete and the PV will transition to Released (since reclaimPolicy is Retain):
Example PV state after PVC deletion:
At this point the underlying data remains at /pv/log on the host. An administrator must manually clean up or change the PV to make it Available again.
Do not forcibly remove PVCs that are in use. The kubernetes.io/pvc-protection finalizer prevents deletion while a Pod references the PVC to protect data integrity. Always delete or update consuming Pods first, then delete the PVC if appropriate.

Quick reference: PV vs PVC


This completes the steps to persist logs first with hostPath, then with a PV/PVC, and explains common gotchas such as accessMode mismatches and PVC protection finalizers.

Watch Video