⌂ Home

HostPath with PV and PVC

Learn how HostPath-backed persistent volumes work in development and lab clusters.

HostPath is simple and useful for demos because it maps directly to a node path, but it also teaches an important lesson: data tied to one node is not portable across the cluster.

Core Concepts

Repository YAML Files:
  • k8s/labs/storage/hostpath-pv-pvc.yaml — HostPath PV, PVC, and Pod manifest
  • k8s/labs/storage/hostpath.yaml — Standalone HostPath volume Pod

Node-bound persistence

The underlying data lives on one node filesystem, so portability is limited by design.

PV and PVC still matter

Even with HostPath, Kubernetes uses the same supply and claim model as any other persistent backend.

Development-first pattern

HostPath is good for labs, local content, and demos, but not a general production storage strategy.

HostPath Binding Flow

1

Create the HostPath PV

Point the volume at a real directory on the host, such as /mnt/data.

2

Request it with a PVC

The claim asks for size and access mode so Kubernetes can bind it to the volume.

3

Mount into the Pod

The Pod references the claim and exposes it inside the container filesystem.

4

Use the data carefully

Writes land on the chosen node path, and that location becomes part of the workload design.

Key point: If the Pod is rescheduled to a different node, the same HostPath data is not automatically available there.

Representative YAML

HostPath PV

apiVersion: v1
kind: PersistentVolume
metadata:
  name: hostpath-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /mnt/data
    type: Directory

PVC and Pod

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: hostpath-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: hostpath-pod
spec:
  containers:
  - name: nginx
    image: nginx
    volumeMounts:
    - name: hostpath-volume
      mountPath: /usr/share/nginx/html
  volumes:
  - name: hostpath-volume
    persistentVolumeClaim:
      claimName: hostpath-pvc

HostPath vs NFS

AspectHostPathNFS
ScopeSingle node pathShared network path
AccessUsually one-node orientedCan support shared access across nodes
Setup effortVery low for labsModerate because a server is required
Typical useLocal experiments and node-specific dataShared files and multi-node access
Design hint: HostPath is great for teaching storage mechanics, but it should also teach its own limits.

How To Use It In Practice

Local labs

Demonstrate PV, PVC, and Pod mounting without standing up extra storage infrastructure.

Node-specific content

Use it when the data is intentionally local to one machine and portability is not required.

Risk awareness

Pair the demo with scheduling, failover, and rescheduling discussions so the tradeoffs stay clear.