Description
A StatefulSet’s volumeClaimTemplates creates a PersistentVolumeClaim (PVC) for each Pod. Keep the claims when data needs to survive Pod replacement.
Potential impact
Unused volumes add cost and maintenance. Removing a volume that is still needed can cause data loss or interrupt service.
Remediation
For persistent data, set capacity, StorageClass, access controls and backups, then test binding and recovery. Before moving to temporary storage, migrate any data you must keep. Check whether the StatefulSet needs recreating, its PVC retention policy and the PersistentVolume (PV) reclaim policy before removing unused data.
Examples
Provide the nginx headless Service for Pod DNS in both alternatives. The first also needs bindable volumes or a storage provisioner.
Before
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: nginx
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
Each of the two Pods requests 1Gi and mounts its volume at /usr/share/nginx/html.
After
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: nginx
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
The second configuration omits the web-content claim and mount. It does not remove existing PVCs or their data by itself.