> For the complete documentation index, see [llms.txt](https://notes.nomanaziz.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.nomanaziz.me/devops/orchestration/kubernetes/9.-k8-statefulset.md).

# 9. K8 StatefulSet

### Stateful Apps

* All DBs
* Any App that stores data
* Stateful apps are not perfect for containerized environments

***

### StatefulSet

* Maintains a sticky identity for each pod
* created from same specification, but not interchangeable
* persistent identifier across rescheduling

#### Scaling DB Apps

* Each pod has separate job
  \*

  ```
  <figure><img src="/files/neltSoZNwosiCliUybaO" alt=""><figcaption></figcaption></figure>
  ```
* They do not use same physical storage
  \*

  ```
  <figure><img src="/files/tK7XuPzKluof9nP4WI3P" alt=""><figcaption></figcaption></figure>
  ```
* Continuously synchronization of data must be done
  * master changes data
  * all workers sync with master
  * new pod clones data with previous pod
* data will be lost when all pods die if persistent volume is not used
* Remote storage should be used for rescheduling
* Next pod is only created if previous is up and running
* Deletion in reverse order, starting from last one
* Each pod gets its own sticky identity i.e fixed predictable pod name and fixed individual dns name which means when pod restarts, ip address changes but name and endpoint stays same

***
