💾
Kubernetes

PersistentVolumeClaim (PVC)

Persistent storage for pods — data survives pod restarts (StatefulSet + PVC pattern)

📋Configuration Files

pvc.yml

yaml
1apiVersion: v1
2kind: PersistentVolumeClaim
3metadata:
4 name: data-pvc
5spec:
6 accessModes:
7 - ReadWriteOnce
8 resources:
9 requests:
10 storage: 1Gi
11 storageClassName: standard

statefulset.yml

StatefulSet mounting the PVC at /data

yaml
1apiVersion: apps/v1
2kind: StatefulSet
3metadata:
4 name: app-with-storage
5spec:
6 serviceName: app-svc
7 replicas: 1
8 selector:
9 matchLabels:
10 app: app-with-storage
11 template:
12 metadata:
13 labels:
14 app: app-with-storage
15 spec:
16 containers:
17 - name: app
18 image: nginx:alpine
19 ports:
20 - containerPort: 80
21 volumeMounts:
22 - name: data
23 mountPath: /data
24 volumes:
25 - name: data
26 persistentVolumeClaim:
27 claimName: data-pvc
📄

Step 01

Apply PVC + StatefulSet

(01)Create PVC then StatefulSet

Linux
1kubectl apply -f pvc.yml
2kubectl get pvc
3kubectl apply -f statefulset.yml
4kubectl get pods,pvc
5kubectl exec app-with-storage-0 -- ls /data