> 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/8.-k8-volumes.md).

# 8. K8 Volumes

### Need for Volumes

Used to persist data in K8

***

### Storage Requirements

1. Storage that dont depend on pod lifecycle
2. Storage must be available on all nodes
3. Storage needs to survive even if cluster crashes

***

### Volume Types

#### 1. Persistent Volume

* a cluster resource
* created via YAML file
* needs actual physical storage like local disk, nfs server or cloud storage
* These volumes are not namespaced
* Local volumes violate 2 and 3 requirement for storage
*

```
<figure><img src="/files/7bkoqnFWdmdqP5Pa4DaM" alt=""><figcaption></figcaption></figure>
```

*

```
<figure><img src="/files/7bvnO5zEGoYhA4t1v65J" alt=""><figcaption></figcaption></figure>
```

#### 2. Persistant Volume Claims (PVC)

* Used by services to claim the created volume for use
* Claims must be in the same namespace
*

```
<figure><img src="/files/9vkJ52m8nrOzhF8jWiKO" alt=""><figcaption></figcaption></figure>
```

**ConfigMap & Secret**

* Do not use PV or PVC
*

```
<figure><img src="/files/Npy4OU3v6IS8EBDtHm1r" alt=""><figcaption></figcaption></figure>
```

#### 3. Storage Class

* Provision Persistent Volumes Dynamically when PVC claims it
* Can be created via YAML file
  \*

  ```
  <figure><img src="/files/rAZkckhohfIOpNgYNCfJ" alt=""><figcaption></figcaption></figure>
  ```

  * Storage Backend is defined in SC component
    * via provisioner attribute
    * each storage backend has own provisioner
    * **internal** provisioner - kubernetes.io
    * **external** provisioner
  * Configure parameters for storage
* Same as PV, it is claimed by PVC in the pods
  \*

  ```
  <figure><img src="/files/ND9B4DjUlrUCAE6stG7t" alt=""><figcaption></figcaption></figure>
  ```

***
