Containers are ephemeral — when a pod dies, everything inside dies too. For databases, you need persistent storage that survives pod restarts. Kubernetes provides this through PersistentVolumes and PersistentVolumeClaims.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: standard
For databases, use StatefulSets instead of Deployments. StatefulSets give each pod a stable hostname (postgres-0, postgres-1) and persistent storage that follows the pod.
In Part 7, we organize our cluster with Namespaces and resource quotas.
← Back to Blog