Volume Configuration
Understanding Volume Configuration Components
Persistent Volume (PV)
A PV is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes.
Persistent Volume Claim (PVC)
A PVC is a request for storage by a user, which can be satisfied by a PV that matches its specifications.
Volume Configuration Workflow
graph TD
A[Create Storage Class] --> B[Define Persistent Volume]
B --> C[Create Persistent Volume Claim]
C --> D[Mount Volume in Pod]
Storage Class Configuration
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: standard-rwo
provisioner: kubernetes.io/host-path
volumeBindingMode: WaitForFirstConsumer
Persistent Volume Configuration Example
apiVersion: v1
kind: PersistentVolume
metadata:
name: example-local-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
storageClassName: standard-rwo
local:
path: /mnt/data
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- worker-node-1
Persistent Volume Claim Configuration
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: example-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: standard-rwo
Volume Mounting in Pod
apiVersion: v1
kind: Pod
metadata:
name: volume-mount-example
spec:
volumes:
- name: storage-volume
persistentVolumeClaim:
claimName: example-pvc
containers:
- name: app-container
image: ubuntu:22.04
volumeMounts:
- name: storage-volume
mountPath: /app/data
Volume Configuration Options
Configuration Option |
Description |
Use Case |
Access Modes |
Defines volume access type |
Controlling read/write permissions |
Storage Class |
Defines storage provisioning |
Dynamic volume creation |
Capacity |
Specifies storage size |
Resource allocation |
Reclaim Policy |
Determines volume lifecycle |
Data preservation |
Reclaim Policies
graph LR
A[Reclaim Policies] --> B[Retain]
A --> C[Delete]
A --> D[Recycle]
Advanced Configuration Considerations
- Use appropriate storage classes
- Implement proper access mode selection
- Configure node affinity for local volumes
- Set appropriate storage capacity
- Define clear reclaim policies
LabEx Recommendation
Explore advanced volume configuration techniques using LabEx's comprehensive Kubernetes learning environments to gain practical experience with persistent storage management.