# 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="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2FPdvNLGPJ62gwzetQK0tz%2Fimage.png?alt=media&#x26;token=99ec5063-158f-4e44-b721-71eb4f27f2d1" alt=""><figcaption></figcaption></figure>
```

*

```
<figure><img src="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2F0IxjrFm0rGnOEoAWbkUO%2Fimage.png?alt=media&#x26;token=be36368c-1d5b-4ba0-9452-b31ace3d3dc1" 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="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2F2rXuh9fGuQw9xPsTEQmc%2Fimage.png?alt=media&#x26;token=dbeef59a-fd70-46e9-ad2f-a62fac0bd6f7" alt=""><figcaption></figcaption></figure>
```

**ConfigMap & Secret**

* Do not use PV or PVC
*

```
<figure><img src="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2Fapj7o9IRGVR4Zlsq8Y7n%2Fimage.png?alt=media&#x26;token=abeacc63-1efe-4048-879a-e7df60af719c" alt=""><figcaption></figcaption></figure>
```

#### 3. Storage Class

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

  ```
  <figure><img src="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2FE3GiOEjlCipVj7i2N7gp%2Fimage.png?alt=media&#x26;token=56efa63b-babf-44bd-8ab3-85682cce44ec" 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="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2FDAt1hwTQAcG7N21vHpLn%2Fimage.png?alt=media&#x26;token=f9f5b9f1-113b-46a2-893e-ae21af0f85f5" alt=""><figcaption></figcaption></figure>
  ```

***


---

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