kubernetes
Kubernetes StatefulSet Generator
Generate a Kubernetes StatefulSet YAML with a PVC template and headless Service. Ready for databases, queues, and other stateful workloads.
Kubernetes StatefulSets
StatefulSets provide three guarantees Deployments don't: stable network identities, stable persistent storage, and ordered startup/shutdown.
Pod Identity
my-app-0 — always pod 0, always uses PVC data-my-app-0
my-app-1 — always pod 1, always uses PVC data-my-app-1
my-app-2 — always pod 2, always uses PVC data-my-app-2DNS for Each Pod
<pod>.<headless-svc>.<namespace>.svc.cluster.local
my-app-0.my-app-headless.default.svc.cluster.localvolumeClaimTemplates
Each pod gets its own PVC. The template generates:
- ›
data-my-app-0for pod 0 - ›
data-my-app-1for pod 1
PVCs outlive pods — data persists through pod restarts and rescheduling.
Common Stateful Workloads
| App | Replicas | Storage |
|---|---|---|
| PostgreSQL (CNPG) | 1 primary + N replicas | Longhorn or cloud SSD |
| Redis Sentinel | 3 (1 primary + 2 replicas) | Longhorn |
| Kafka | 3+ | Fast local NVMe |
| Zookeeper | 3 | Standard SSD |
Key Terms
Full glossary →kubeadm
A tool for bootstrapping Kubernetes clusters. It automates the setup of control plane components and joining worker nodes, following Kubernetes best practices.
etcd
A distributed key-value store used by Kubernetes to store all cluster state and configuration. etcd is the single source of truth for the entire cluster.
cert-manager
A Kubernetes controller for automating TLS certificate management. cert-manager can issue certificates from Let's Encrypt, Vault, or internal CAs, and automatically renews them.
Helm
A package manager for Kubernetes. Helm charts bundle Kubernetes manifests into reusable packages with configurable values, versioned and published to chart repositories.
Frequently Asked Questions
When should I use a StatefulSet vs a Deployment?
Use a StatefulSet when your pods need stable network identities (predictable pod names like my-app-0, my-app-1), stable persistent storage (each pod gets its own PVC that follows it), or ordered startup/shutdown. Databases (PostgreSQL, MongoDB, Redis Sentinel), message queues (Kafka, RabbitMQ), and distributed caches are all StatefulSet use cases. Use a Deployment for stateless apps where any pod is interchangeable.
What is a headless Service and why does a StatefulSet need one?
A headless Service (clusterIP: None) doesn't get a virtual IP. Instead, DNS returns individual pod IPs directly. StatefulSets require a headless Service to create stable DNS entries for each pod: my-app-0.my-app-headless.default.svc.cluster.local. This allows pods to discover and communicate with specific replicas — essential for clustering protocols (Raft, Paxos, Galera).
Can I scale a StatefulSet down safely?
Yes, but with caution. Kubernetes scales down StatefulSets in reverse order (my-app-2 first, then my-app-1, etc.) and respects PodDisruptionBudgets. The PVC is NOT deleted when you scale down — the pod's data persists. If you scale back up, the same PVC is reattached. To delete PVCs you must do it manually. Never scale below quorum for clustered apps (e.g. don't scale an odd-node etcd from 3→2).
How do I update a StatefulSet?
StatefulSets support RollingUpdate (default) and OnDelete strategies. With RollingUpdate, pods are updated one at a time in reverse ordinal order — my-app-2 first. This ensures the cluster always has running nodes during an upgrade. Set partition: N to do a staged rollout where only pods with ordinal ≥ N are updated, letting you test on one pod before rolling to all.
Related Calculators
Related Guides
kubernetes
CI/CD for Kubernetes with GitHub Actions: A Complete Guide (2026)
A practical walkthrough of building a full GitHub Actions pipeline that builds a container image, pushes it to a registry, and deploys to Kubernetes — with secrets handling, rollback, and Helm support.
kubernetes
ArgoCD vs Flux: Choosing a GitOps Tool for Kubernetes in 2026
A no-fluff comparison of ArgoCD and Flux for GitOps on Kubernetes — covering architecture, UI, Helm support, multi-tenancy, and when to pick each one.
kubernetes
Hetzner vs DigitalOcean for Kubernetes in 2026: An Honest Comparison
Hetzner is 3–5× cheaper than DigitalOcean for equivalent Kubernetes compute. But DO has managed K8s, better global coverage, and a larger app marketplace. Here's when each is the right choice.