update kuber doc: update pv
This commit is contained in:
@@ -2,63 +2,61 @@
|
|||||||
|
|
||||||
## 📦 What is a Persistent Volume (PV)?
|
## 📦 What is a Persistent Volume (PV)?
|
||||||
|
|
||||||
A **Persistent Volume (PV)** is a piece of storage in a Kubernetes cluster that is either:
|
A **Persistent Volume (PV)** is a piece of storage in a Kubernetes cluster that can be:
|
||||||
|
|
||||||
* Pre-provisioned by an administrator, or
|
- **Pre-provisioned** by an administrator, or
|
||||||
* Dynamically provisioned using **StorageClasses**.
|
- **Dynamically provisioned** using a **StorageClass**.
|
||||||
|
|
||||||
It allows data to **persist beyond the lifecycle of individual Pods**.
|
> PVs allow data to **persist beyond the lifecycle of individual Pods**.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📁 PV Storage Options
|
## 📁 PV Storage Options
|
||||||
|
|
||||||
1. **HostPath**
|
### 1. **HostPath**
|
||||||
|
- Mounts a file or directory from the host node’s filesystem into a Pod.
|
||||||
|
- Only suitable for **single-node testing or development** environments.
|
||||||
|
|
||||||
* Mounts a file or directory from the host node’s filesystem into your Pod.
|
### 2. **Persistent Volume (PV) & Persistent Volume Claim (PVC)**
|
||||||
* Useful only for single-node testing or development.
|
- **PV**: Represents the actual physical or virtual storage resource.
|
||||||
|
- **PVC**: A user's request for specific storage resources and access modes.
|
||||||
2. **Using PV and PVC**
|
|
||||||
|
|
||||||
* **PV (Persistent Volume):** Represents the actual storage resource.
|
|
||||||
* **PVC (Persistent Volume Claim):** A user's request for storage resources and access.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🧱 Kubernetes Storage Layers
|
## 🧱 Kubernetes Storage Architecture
|
||||||
|
|
||||||
1. **Persistent Volume (PV)** – The actual storage unit.
|
1. **Persistent Volume (PV)** – The actual storage unit, managed by the admin or provisioned dynamically.
|
||||||
2. **Persistent Volume Claim (PVC)** – A request for that storage.
|
2. **Persistent Volume Claim (PVC)** – A user’s request for a certain amount and type of storage.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🔄 PV Lifecycle States
|
## 🔄 PV Lifecycle Phases
|
||||||
|
|
||||||
| State | Description |
|
| **State** | **Description** |
|
||||||
| ------------ | ------------------------------------------ |
|
|---------------|---------------------------------------------|
|
||||||
| Provisioning | PV is being prepared. |
|
| Provisioning | PV is being created or initialized. |
|
||||||
| Binding | PV is bound to a PVC. |
|
| Binding | PV is bound to a PVC. |
|
||||||
| Using | PV is in use by a Pod. |
|
| Using | PV is in use by a Pod. |
|
||||||
| Releasing | PVC is deleted; PV becomes unbound. |
|
| Releasing | PVC is deleted; PV becomes unbound. |
|
||||||
| Reclaiming | Reclaim policy is applied: |
|
| Reclaiming | Based on reclaim policy: |
|
||||||
| | • `Delete` – Remove the storage. |
|
| | - `Delete`: Remove the storage. |
|
||||||
| | • `Recycle` – Basic scrub (deprecated). |
|
| | - `Recycle`: Basic scrub (deprecated). |
|
||||||
| | • `Retain` – Manual intervention required. |
|
| | - `Retain`: Manual cleanup required. |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🔒 PV Access Modes
|
## 🔒 PV Access Modes
|
||||||
|
|
||||||
| Mode | Description |
|
| **Mode** | **Description** |
|
||||||
| ------ | ---------------------------------------------- |
|
|------------|-------------------------------------------------|
|
||||||
| `RWO` | **ReadWriteOnce** – One node can read/write |
|
| `RWO` | **ReadWriteOnce** – One node can read/write. |
|
||||||
| `ROX` | **ReadOnlyMany** – Multiple nodes read-only |
|
| `ROX` | **ReadOnlyMany** – Multiple nodes can read. |
|
||||||
| `RWX` | **ReadWriteMany** – Multiple nodes read/write |
|
| `RWX` | **ReadWriteMany** – Multiple nodes can read/write. |
|
||||||
| `RWOP` | **ReadWriteOncePod** – Only one Pod can use it |
|
| `RWOP` | **ReadWriteOncePod** – Only one Pod can mount it with read/write access. |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🛠️ CLI Commands to Manage PVs
|
## 🛠️ CLI Commands to Manage PVs & PVCs
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# List all Persistent Volumes
|
# List all Persistent Volumes
|
||||||
@@ -73,7 +71,7 @@ kubectl edit pvc -n <namespace> <pvc-name>
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🚀 Example 1: Deployment with `hostPath` Volume
|
## 🚀 Example: Deployment with `hostPath` Volume
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
@@ -81,17 +79,15 @@ kind: Deployment
|
|||||||
metadata:
|
metadata:
|
||||||
name: app-1
|
name: app-1
|
||||||
namespace: dev
|
namespace: dev
|
||||||
labels:
|
|
||||||
app.kubernetes.io/name: nginx
|
|
||||||
spec:
|
spec:
|
||||||
replicas: 3
|
replicas: 3
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app.kubernetes.io/name: nginx
|
name: nginx
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app.kubernetes.io/name: nginx
|
name: nginx
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: nginx
|
- name: nginx
|
||||||
@@ -108,86 +104,107 @@ spec:
|
|||||||
type: DirectoryOrCreate
|
type: DirectoryOrCreate
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Valid `hostPath` Types:
|
||||||
|
- `DirectoryOrCreate`
|
||||||
|
- `Directory`
|
||||||
|
- `FileOrCreate`
|
||||||
|
- `File`
|
||||||
|
- `Socket`
|
||||||
|
- `CharDevice`
|
||||||
|
- `BlockDevice`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📂 Example 2: NFS-backed Persistent Volume
|
## 📄 Example: Static Persistent Volume (PV)
|
||||||
|
|
||||||
### 🧩 PersistentVolume Definition
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: PersistentVolume
|
kind: PersistentVolume
|
||||||
metadata:
|
metadata:
|
||||||
name: pv1
|
name: pv001
|
||||||
spec:
|
spec:
|
||||||
capacity:
|
capacity:
|
||||||
storage: 5Gi
|
storage: 128Mi
|
||||||
volumeMode: Filesystem
|
|
||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteMany
|
- ReadWriteMany
|
||||||
persistentVolumeReclaimPolicy: Retain
|
persistentVolumeReclaimPolicy: Retain
|
||||||
storageClassName: custom-name
|
|
||||||
mountOptions:
|
|
||||||
- hard
|
|
||||||
- nfsvers=4.1
|
|
||||||
nfs:
|
|
||||||
path: /nfs/data
|
|
||||||
server: 192.168.1.10
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 📄 PersistentVolumeClaim
|
---
|
||||||
|
|
||||||
|
## 📄 Example: Persistent Volume Claim (PVC)
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: PersistentVolumeClaim
|
kind: PersistentVolumeClaim
|
||||||
metadata:
|
metadata:
|
||||||
name: pvc1
|
name: pvc-2
|
||||||
namespace: ns-test
|
namespace: db
|
||||||
spec:
|
spec:
|
||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteMany
|
- ReadWriteOnce
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 1Gi
|
storage: 64Mi
|
||||||
storageClassName: custom-name
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 🚀 Deployment Using PVC
|
> ✅ To bind a PVC to a specific PV, add `volumeName: <pv-name>` in the PVC spec:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: apps/v1
|
volumeName: pv001
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: app-1
|
|
||||||
namespace: dev
|
|
||||||
labels:
|
|
||||||
app.kubernetes.io/name: nginx
|
|
||||||
spec:
|
|
||||||
replicas: 3
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app.kubernetes.io/name: nginx
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app.kubernetes.io/name: nginx
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: nginx
|
|
||||||
image: nginx
|
|
||||||
ports:
|
|
||||||
- containerPort: 80
|
|
||||||
volumeMounts:
|
|
||||||
- name: nginx-log
|
|
||||||
mountPath: /var/log/nginx
|
|
||||||
volumes:
|
|
||||||
- name: nginx-log
|
|
||||||
persistentVolumeClaim:
|
|
||||||
claimName: pvc1
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📝 Common Mistakes Fixed
|
## 🌐 NFS-Based Persistent Volume
|
||||||
|
|
||||||
|
### Persistent Volume (PV)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolume
|
||||||
|
metadata:
|
||||||
|
name: pv-nfs-2
|
||||||
|
spec:
|
||||||
|
capacity:
|
||||||
|
storage: 128Mi
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteMany
|
||||||
|
persistentVolumeReclaimPolicy: Retain
|
||||||
|
storageClassName: nginx-files
|
||||||
|
mountOptions:
|
||||||
|
- hard
|
||||||
|
- nfsvers=4.2
|
||||||
|
nfs:
|
||||||
|
path: /root/Nginx_Files
|
||||||
|
server: 192.168.6.160
|
||||||
|
```
|
||||||
|
|
||||||
|
### Persistent Volume Claim (PVC)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: pvc-1
|
||||||
|
namespace: db
|
||||||
|
spec:
|
||||||
|
volumeName: pv-nfs-2
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteMany
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 64Mi
|
||||||
|
storageClassName: nginx-files
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🏗️ Static StorageClass for Pre-Provisioned Volumes
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: storage.k8s.io/v1
|
||||||
|
kind: StorageClass
|
||||||
|
metadata:
|
||||||
|
name: nginx-files
|
||||||
|
provisioner: kubernetes.io/no-provisioner
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user