Review StatefulSet persistent-storage requirements

Review persistence needs together with capacity and retention policies.

Description

A StatefulSet’s volume_claim_template requests a PersistentVolumeClaim (PVC) for each Pod. Keep the claim and size it for data that must survive Pod replacement.

Potential impact

Keeping temporary or reproducible data adds storage, backup and disposal costs. Deleting a claim that is still needed can lose data or disrupt service.

Remediation

Set backup, encryption and retention policies for persistent data. Before dropping a claim template, migrate data you must keep. Check the plan for StatefulSet recreation and review PVC retention and volume reclaim policies before cleaning up unneeded data.

Examples

Both excerpts need a Pod template and the prometheus headless Service for Pod DNS.

Before

hcl
resource "kubernetes_stateful_set" "example" {
  metadata {
    name = "prometheus"
  }

  spec {
    service_name = "prometheus"

    selector {
      match_labels = {
        app = "prometheus"
      }
    }

    volume_claim_template {
      metadata {
        name = "data"
      }

      spec {
        access_modes       = ["ReadWriteOnce"]
        storage_class_name = "standard"

        resources {
          requests = {
            storage = "16Gi"
          }
        }
      }
    }
  }
}

After

hcl
resource "kubernetes_stateful_set" "example" {
  metadata {
    name = "prometheus"
  }

  spec {
    service_name = "prometheus"

    selector {
      match_labels = {
        app = "prometheus"
      }
    }
  }
}

The first configuration requests 16Gi from the standard StorageClass per Pod. The second describes a workload without persistent storage. Omitting the template does not itself delete existing PVCs or their data.

References