top of page

What is a Kubernetes StatefulSet?

What is a Kubernetes Stateful Set?

Kubernetes Statefulsets are used specifically to run stateful, replicated services, like Databases inside the Kubernetes cluster.

Configuration of a Stateful Set:

apiVersion: apps/v1

kind: StatefulSet


  name: mysql


  replicas: 3




        - name: mysql

          image: mysql:8.0


            - name: MYSQL_DATABASE

              value: my-db

            - name: MYSQL_ROOT_PASSWORD



                  name: mysql-credentials

                  key: password


            - name: mysql

              containerPort: 3306

The main part of the Statefulset that makes it able to run databases is that each replica pod gets assigned a unique ID. This ID sticks to the pod even when it's rescheduled to another worker node. Through this unique ID, the pod retains the connection to the volume that holds the state of the database. However, because when rescheduling the pod, the volume gets detached and then reattached again, the storage volumes must be on a remote persistent disk, which means the storage needs to be hosted outside of the cluster itself.

So overall, each replica pod in a stateful set has its state and data. So when it gets restarted, it needs to regain that state. This means we can't use local storage for stateful sets since local storage is bound to a node, so when the pod is rescheduled to another node, its previous state won't be available for it. Instead, it should use remote storage that isn't bound to any specific node. ✅


Get started in Kubernetes with this 1 hour crash course:


Albert Dexter
Albert Dexter
Oct 01, 2023

Education is the key to unlocking endless opportunities and personal growth provides valuable insights for students aiming for academic success. Trusted writing services can be essential in refining essays, ensuring quality and depth. Embrace these resources to enhance your learning experience, guiding you toward excellence in your educational endeavors. Seize the chance to excel with the right support.


chenna Reddy
chenna Reddy
Aug 27, 2023

Hi Nana,

I am a big follower of your content.

I have a doubt and I am trying to fix it but not able to do it. Can you provide your suggestions on how I can do this.

Requirement is I will have to copy mongodb.conf into /data/db instead of /etc/mongo, I have tried subpath but it is failing.

bottom of page