# 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="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2FUgEDlOOgPOxe1sN7RNKX%2Fimage.png?alt=media&#x26;token=1f35fe07-fdef-490a-bc9a-a053128fdd94" alt=""><figcaption></figcaption></figure>
  ```
* They do not use same physical storage
  \*

  ```
  <figure><img src="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2F7kgVdI8eAtttfJyz7tqv%2Fimage.png?alt=media&#x26;token=376c0327-0717-4cff-b06a-391e4f72b47b" 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

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.nomanaziz.me/devops/orchestration/kubernetes/9.-k8-statefulset.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
