Request a Call Back

Should I use StatefulSets or Deployments for my database on K8s?


I am planning to move our MongoDB and PostgreSQL instances into our Kubernetes cluster to simplify our CI/CD pipeline. However, I’m confused about whether I should use a standard Deployment or a StatefulSet. What are the key differences in how Kubernetes handles storage, networking, and scaling for these two types of resources when dealing with persistent data?


   2024-11-12 in Cloud Technology by Christopher Garcia | 11439 Views


All answers to this question.


For databases, you should almost always use StatefulSets. Unlike Deployments, StatefulSets provide a stable, unique network identifier for each pod (e.g., pod-0, pod-1), which is crucial for database clustering and replication. They also ensure that when a pod is rescheduled, it reconnects to the same Persistent Volume (PV). In a Deployment, pods are interchangeable and storage is shared, which can lead to data corruption if multiple pods try to write to the same volume simultaneously. StatefulSets handle the ordered, graceful deployment and scaling required for stateful apps.

   Answered 2024-11-14 by Dorothy Martinez


What kind of storage class are you using? Even with a StatefulSet, the underlying storage needs to support the specific access modes (like ReadWriteOnce) required by your database to ensure consistency.

   Answered 2024-11-15 by Richard Moore

  • Richard, we are using AWS EBS with the gp3 storage class. It supports ReadWriteOnce, which fits the StatefulSet model perfectly. I was worried about how the secondary nodes would find the primary after a restart, but Dorothy's explanation about the stable network ID via a Headless Service cleared that up. We'll be setting up a Headless Service today to manage the DNS for our Mongo members.

       Commented 2024-11-16 by Christopher Garcia


StatefulSets also give you ordered updates. This means it updates one pod at a time, ensuring your database cluster doesn't lose its quorum during a rollout.

   Answered 2024-11-17 by Margaret White

  • Exactly. Margaret’s point about quorum is why we use StatefulSets for our ETCD and Consul clusters too. It's much safer than a rolling update in a Deployment.

       Commented 2024-11-18 by Dorothy Martinez



Write a Comment

Your email address will not be published. Required fields are marked (*)




Suggested Questions

Introduction to Project Management..
Posted 2026-07-07 by learnersera.
Balancing Link Metrics With Structural Entity Maps..
Posted 2025-05-12 by learnersera.
Balancing Link Metrics With Structural Entity Maps..
Posted 2025-05-12 by learnersera.
Impact of Entity Authority on Organic Competitive..
Posted 2025-01-04 by learnersera.
Backlinks vs Entity Authority for SEO Rankings..
Posted 2025-04-14 by learnersera.
How are modern agile organizations evaluating scrum..
Posted 2025-07-19 by learnersera.
Is a specialized technical degree required to..
Posted 2025-10-05 by learnersera.
How heavily do hiring managers weigh professional..
Posted 2025-09-12 by learnersera.

Disclaimer

  • "PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc.
  • "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA.
  • COBIT® is a trademark of ISACA® registered in the United States and other countries.
  • CBAP® and IIBA® are registered trademarks of International Institute of Business Analysis™.

We Accept

We Accept

Follow Us

 facebook icon
 twitter
linkedin

Instagram
twitter
Youtube

Quick Enquiry Form

WhatsApp Us  /      +1 (713)-287-1187