Review StatefulSet persistent storage requirements

Check data retention needs and manage the capacity and lifecycle of required volumes.

Description

StatefulSet volumeClaimTemplates create a PersistentVolumeClaim for each Pod. This is appropriate for workloads that need persistent data; a storage request alone is not a reason to remove it. For workloads that need only temporary data, unnecessary persistent storage can increase costs and the amount of retained data.

Potential impact

  • Unneeded volumes and retained data can increase cost and management work.
  • Removing volumes without checking retention needs can cause data loss or service interruption.

Remediation

  • Determine whether the workload needs persistent storage. If it does, configure suitable capacity, a StorageClass, access controls and backups, and test binding and recovery.
  • If persistent storage is unnecessary, plan data migration and assess whether the StatefulSet must be recreated before changing the configuration. Check PVC retention and PV reclaim policies, and remove only data that is no longer needed.

Examples

These existing nginx excerpts compare persistent-volume use. Provide the nginx Service and storage provisioning separately. They are alternative configurations, not a patch that directly removes volumeClaimTemplates from an existing StatefulSet.

Before

yaml
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 Pod requests a 1Gi PVC mounted at the web-content path. This can be appropriate when persistent data is required.

After

yaml
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

Persistent-volume requests and mounts are omitted. This does not automatically delete existing PVCs or data; choose it only when data retention requirements allow.

References