_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

StatefulSets for Databases

21. 07. 2025 1 min read intermediate

Cloud Expert

StatefulSets for Databases

KubernetesStatefulSetDatabase 3 min read

StatefulSets for stateful applications in Kubernetes. Ordered deployment, stable network identity.

Why StatefulSet?

Unlike Deployments: stable hostname (pod-0, pod-1), ordered creation/deletion, persistent volumes per pod.

Example

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: postgres
  replicas: 3
  selector:
    matchLabels: {app: postgres}
  template:
    metadata:
      labels: {app: postgres}
    spec:
      containers:
        - name: postgres
          image: postgres:16
          ports: [{containerPort: 5432}]
          volumeMounts:
            - {name: data, mountPath: /var/lib/postgresql/data}
  volumeClaimTemplates:
    - metadata: {name: data}
      spec:
        accessModes: [ReadWriteOnce]
        resources: {requests: {storage: 100Gi}}

Headless Service

StatefulSet requires a headless service (clusterIP: None) for DNS records: postgres-0.postgres.default.svc.cluster.local

Summary

StatefulSet for databases, message queues and other stateful workloads. Consider managed DB (RDS, Cloud SQL) for simpler operations.

Need Help with Implementation?

Our team has experience designing and implementing modern architectures. We’re happy to help.

Free Consultation

Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.