>_ IzzyLab

Hands-on task

This task is step 18 of the course “Kubernetes: manifests from Namespace to RBAC”

k8s: StatefulSet with volumes

hard~15 min

In /root/sts.yaml there is a StatefulSet db (image postgres, 2 replicas), but with no persistent storage — data will be lost when a pod restarts. Fix the manifest: add volumeClaimTemplates (a PVC data of 1Gi) mounted at /var/lib/postgresql/data.

Edit the file in the Editor tab.

What you'll practise:
  • kubernetes
  • statefulset
  • volumeclaimtemplates
  • pvc
  • persistent storage

Topic breakdown

A StatefulSet is a controller for stateful applications (databases): it gives pods stable names and, importantly, persistent storage via volumeClaimTemplates. This isn't a ready-made PVC but a TEMPLATE: Kubernetes creates a separate volume per pod (data-db-0, data-db-1), and each pod keeps exactly its own volume across restarts. The template is described as a PVC spec — accessModes and a storage request in resources.requests.storage. Separately, the container needs a volumeMounts mounting this volume into the application's data directory, otherwise the declared storage won't actually be attached anywhere.

What's checked

  1. manifest is valid (kubeconform)
  2. kind = StatefulSet
  3. volumeClaimTemplates with PVC data
  4. PVC data requests 1Gi
  5. the data volume is mounted at the data directory

What it looks like