24 June 2023
The default container file system is shortlived.
The contents will exist as long as the container exists.
For persistant data.
Store data outside the container file system.
Store the persistent data as an abstract resource and consumed by the pods.
Container > Persistent Volume Claim > Persistent Volume > External Storage
You need a PVC associated with the container to use the volume.
Volume types determine handling of the storage.
NFS
Cloud
ConfigMaps and Secrets
Directory on the K8s node.
Volumes and volumeMounts
So we need a volumes under the spec as well as a volumeMounts unde the container block for the deined container.
example.yaml
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: registry.k8s.io/test-webserver
name: test-container
volumeMounts:
- mountPath: /test-pd
name: test-volume
volumes:
- name: test-volume
hostPath:
path: /data
Sharing Volumes between Containers.
needs to be tested…..
shared-example.yaml
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: registry.k8s.io/test-webserver
name: test-container-input
volumeMounts:
- mountPath: /input
name: test-volume
- image: registry.k8s.io/test-webserver
name: test-container-output
volumeMounts:
- mountPath: /output
name: test-volume
volumes:
- name: test-volume
hostPath:
path: /data
Common Volume Types
hostPath
emptyDir
hostPath