kubernetes petset on google cloud
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
PetSet is the historical name for what Kubernetes now calls a StatefulSet. If you are deploying a stateful workload on Google Cloud today, the correct workload object is StatefulSet, not PetSet. The underlying use case is the same: stable pod identities, persistent storage, and ordered rollout behavior for applications such as databases, brokers, and clustered services.
On Google Kubernetes Engine, a modern answer means combining a StatefulSet with a headless Service and persistent volumes. Once those pieces are in place, each replica gets a stable pod name and a durable volume that survives pod rescheduling.
Why StatefulSet Replaced PetSet
Stateful workloads differ from stateless replicas in two important ways:
- each pod may need a stable network identity
- each pod may need storage that stays attached to that logical replica over time
A Deployment does not guarantee those identities. A StatefulSet does. That is why the old PetSet concept evolved into today's StatefulSet API.
In GKE, that means you should use a StatefulSet whenever replica identity matters, such as db-0, db-1, and db-2, each with its own persistent volume.
Start With a Headless Service
A StatefulSet relies on a headless Service for stable DNS identities.
With this in place, pods get predictable names such as web-0.web, web-1.web, and so on within the cluster DNS system.
Create the StatefulSet
A basic GKE-friendly StatefulSet looks like this:
Apply it with:
Each replica gets its own persistent volume claim derived from volumeClaimTemplates. That is the storage behavior stateful workloads usually need.
What This Gives You on GKE
With a StatefulSet, GKE provides the Kubernetes guarantees that matter for stateful apps:
- ordered pod creation and deletion
- stable pod names
- durable volume attachment per replica
- rolling updates that respect pod ordering
This is important for clustered systems that bootstrap in sequence or replicate data between known peers.
It is also worth remembering what Kubernetes does not do for you. A StatefulSet helps with orchestration identity and storage binding, but it does not turn any application into a distributed database automatically. Your application still needs its own clustering and recovery logic.
Operate It Carefully
Check the rollout and the claims after deployment:
When scaling, Kubernetes preserves the pod ordinals. If you scale from 3 replicas down to 1, the PVCs are not automatically deleted. That is intentional for data safety.
If you need to delete the workload entirely, plan the storage lifecycle explicitly. Stateful storage should never disappear by surprise.
Common Pitfalls
The biggest mistake is following old PetSet wording literally and searching for an obsolete API object. The current object is StatefulSet.
Another issue is forgetting the headless Service. Without it, stable pod DNS identities do not work as expected.
A third problem is assuming persistent volumes disappear automatically when the StatefulSet scales down or is deleted. They generally do not, and that is usually the safe behavior.
Summary
- '
PetSetis the historical predecessor of today'sStatefulSet.' - On Google Cloud and GKE, use
StatefulSetfor workloads that need stable identity and persistent storage. - Pair the
StatefulSetwith a headless Service for stable network names. - Use
volumeClaimTemplatesso each replica gets its own persistent volume claim. - Treat storage lifecycle as a deliberate operational decision, not an automatic cleanup side effect.
Related reading
- Kubernetes pod cannot connect to external Database
- Kubernetes POD delete with Pattern Match or Wildcard
- Kubernetes pod distribution amongst nodes
- Kubernetes pod distribution amongst nodes with preferred mode
- Kubernetes pods are stuck after scale up AWS. Multi-Attach error for volume
- Kubernetes pull from multiple private docker registries
- Kubernetes pod not READY
- Kubernetes Port Forwarding - Connection refused

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.