-
Notifications
You must be signed in to change notification settings - Fork 3
Kubernetes Volumes
Essentialy - a directory that will be accessible by POD, preserving state independently of POD lifecycle.
Example (simplest) usage of volume
apiVersion: v1
kind: Pod
metadata:
labels:
app: pod
name: example
spec:
containers:
- image: httpd
name: example
volumeMounts:
- mountPath: /var/tmp
name: vartmp
volumes:
- name: vartmp
hostPath:
path: /mnt/testing
There are numerous volume types that can be used, hostPath
is actually the most test-purpose only.
It is possible to mount ConfigMap
as a volume.
Typically you have PersistentVolume
(PV) resource (or have some Cloud provider prepare that for you) and you just mount it to the PODs.
The persistentVolumeClaim
(PVC) is used as that glue. The PVC represents the request for storage.
There are two main types of Persistent Volumes provisioning:
-
Static
It is the administrator that prepares volumes. Useselector
in PVC, without providingstorageClassName
to use static provisioning -
Dynamic
Based onStorageClass
thePersistentVolume
will be automatically created for given PVC. UsestorageClassName
.
Example POD with PersistentVolume
Statically provisioned (StorageClass
is not used at all)
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
labels:
name: example-pv
spec:
capacity:
storage: 1Mi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
##storageClassName: local-storage
#hostPath:
# path: /mnt/testing
local:
path: /mnt/testing
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- k8s1
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: example-pvc
spec:
##storageClassName: local-storage
selector:
matchLabels:
name: example-pv
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Mi
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: pod
name: example
spec:
containers:
- image: httpd
name: example
volumeMounts:
- mountPath: /var/tmp
name: vartmp
volumes:
- name: vartmp
persistentVolumeClaim:
claimName: example-pvc
- General
- OS
- Networks
- Configuration
- Protocols
- Link layer
- Sockets
- Routing
- Tunneling
- Debugging
- LoRa
- Virtualization
- Infrastructure as a code
- Desktop environments
- Monitoring
- Benchmarking