A file stored only in a container’s writable layer does not automatically follow a replacement container. Connect a directory on wk01 through a local PersistentVolume and claim, then compare the files before and after recreating the Pod. The storage remains tied to that node.
Table of Contents
1. Node dependency of local PV
local PV uses disks from a specific node. Although Pods can be recreated, data is not replicated to other nodes in the event of a node failure. This is an exercise to check this limitation, and it is not a recommended configuration to place the actual service DB on a single local PV. When multi-node storage becomes necessary, the roles of CSI and data replication are examined separately.
# wk01에서 실행. 처음 만드는 빈 실습 디렉터리
sudo install -d -o 1000 -g 1000 -m 0770 /var/local/k8s-lab/data
sudo ls -ld /var/local/k8s-lab/data
The container uses UID/GID 1000, so set the host directory ownership accordingly. Do not work around a permission error with chmod 777. This series assumes permissive SELinux. With enforcing SELinux, also check volume labels and runtime policy.
2. StorageClass·PV·PVC
Save the contents below to ~/k8s-lab/app/local-storage.yaml in cp01. StorageClass and PV are cluster scoped, while PVC belongs to the lab namespace.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-lab
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-local-wk01
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes: [ReadWriteOnce]
persistentVolumeReclaimPolicy: Retain
storageClassName: local-lab
local:
path: /var/local/k8s-lab/data
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values: [wk01]
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: local-data
namespace: lab
spec:
accessModes: [ReadWriteOnce]
storageClassName: local-lab
resources:
requests:
storage: 1Gi
kubectl apply -f ~/k8s-lab/app/local-storage.yaml
kubectl get pv
kubectl -n lab get pvc
If the PVC is Pending, first check WaitForFirstConsumer. Binding waits for the Pod placement requirements so that a PV on a suitable node can be selected. Do not bypass the scheduler with nodeName. storage: 1Gi does not automatically impose a disk quota on the local directory; manage the actual free space separately.
3. Pod for file recording
Save the following file as volume-check.yaml. Using a stand-alone Pod for practice, we only compare before and after regeneration, and delete the Pod when the practice is over.
apiVersion: v1
kind: Pod
metadata:
name: volume-check
namespace: lab
spec:
restartPolicy: Never
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
seccompProfile:
type: RuntimeDefault
containers:
- name: writer
image: busybox:1.37.0
command: [sh, -c]
args:
- 'date >> /data/history.log; cat /data/history.log; sleep 3600'
resources:
requests:
cpu: 10m
memory: 16Mi
limits:
cpu: 100m
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: [ALL]
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: local-data
cd ~/k8s-lab/app
kubectl apply -f volume-check.yaml
kubectl -n lab wait --for=condition=Ready pod/volume-check --timeout=120s
kubectl -n lab get pod volume-check -o wide
kubectl -n lab get pvc local-data
kubectl -n lab logs volume-check
Verify that the Pod’s NODE is wk01 and its PVC is Bound. ReadWriteOnce means reading and writing are allowed on one node. This does not mean that only one Pod is accessed. If multiple Pods write to the same file, separate consistency processing is required.
4. Check files after pod regeneration
kubectl -n lab delete pod volume-check
kubectl apply -f volume-check.yaml
kubectl -n lab wait --for=condition=Ready pod/volume-check --timeout=120s
kubectl -n lab logs volume-check
# 실습 종료: 이후 drain을 방해하지 않도록 단독 Pod 삭제
kubectl -n lab delete pod volume-check
Look in the second startup log to see the old and new records together. What you can check with this result is whether you have remounted the wk01 directory like or . This is not a recovery test for failure of the node itself. PV and PVC are reserved for later backup exercises.
5. Pending·Released and Retain
| Condition/Symptoms | Check first |
|---|---|
| PVC Pending before Pod creation | WaitForFirstConsumer Is it waiting? |
| Pending even after Pod creation | Node name·PV affinity·taint·Requested capacity·StorageClass |
| Permission denied | Host directory owner·UID/GID·SELinux |
| PV Released after PVC deletion | Retain policy and previous claimRef and data handover procedures |
| Pod Pending when wk01 fails | Node dependency of local PV, absence of replication function |
Retain is a recall policy that does not automatically clean up stored data when a PVC is deleted. It does not create backups or perform replication. When reusing PV, first determine ownership and handling of residual data. If you delete claimRef and connect to another app, data may be mixed. Multi-Node Write co-designs CSI storage and backup to fit your needs.
reference material
- PersistentVolume and Recovery Policy
- Constraints on local volumes
- Delayed Binding with StorageClass
- Kubernetes Storage Overview
official documents and distribution files confirmed: October 18, 2026. The output is an example to determine completion and may vary depending on the environment.



