Skip to content

Volumes

Persistent storage volumes are provided through Ceph Block Devices and can be attached to containers as Kubernetes Volumes. They are not automatically deleted along with the container.

To use it, set storageClassName: rook-ceph-fs, and select accessModes:

  • ReadWriteOnce means only a single container can access the volume.
  • ReadOnlyMany for constant data which is defined when the volume is created.
  • ReadWriteMany for network file system access between multiple containers.

Example

Following is an example of accessModes: ReadWriteMany

storage.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: testpod-storage
spec:
  accessModes:
  - ReadWriteMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 1Gi
  storageClassName: rook-ceph-fs
pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: podname
spec:
  containers:
  - name: bb
    image: busybox
    command:
      - sleep
      - infinity
    resources:
      requests:
        memory: "128Mi"
        cpu: "500m"
      limits:
        memory: "128Mi"
    volumeMounts:
    - name: shared-volume
      mountPath: /shared
  volumes:
  - name: shared-volume
    persistentVolumeClaim:
      claimName: testpod-storage

Create the volume, and two pods sharing it

kubectl create -f storage.yaml
sed "s/podname/testpod0/" pod.yaml | kubectl create -f -
sed "s/podname/testpod1/" pod.yaml | kubectl create -f -
kubectl exec testpod0 -- sh -c "echo 'Hello, world\!' >> /shared/hello"
kubectl exec testpod1 -- sh -c "cat /shared/hello"

Hello, world!

Last update: 2023-01-25
Created: 2023-01-05