Mounting a volume in Block mode
To connect a volume in volumeMode: Block
, perform the following steps.
Create a PersistentVolumeClaim object
-
To create a volume in Block mode, set the
spec.volumeMode
field value toBlock
.Save the following PersistentVolumeClaim creation specification to a YAML file named
pvc-block.yaml
.To learn more about the
PersistentVolumeClaim
creation specification, see the Kubernetes documentation . -
Create a
PersistentVolumeClaim
:kubectl create -f pvc-block.yaml
Result:
persistentvolumeclaim/pvc-block created
Create a pod with the mounted volume
-
When creating a volume pod in Block mode, specify the
spec.containers.volumeDevices
field.Save the following pod creation specification to a YAML file named
pod.yaml
.To learn more about the pod creation specification, see the Kubernetes documentation
.apiVersion: v1 kind: Pod metadata: name: pod spec: containers: - name: app image: ubuntu command: ["/bin/sh"] args: ["-xc", "/bin/dd if=/dev/block of=/dev/null bs=1K count=10; /bin/sleep 3600"] volumeDevices: - devicePath: /dev/block name: persistent-storage volumes: - name: persistent-storage persistentVolumeClaim: claimName: pvc-block
-
Run the following command:
kubectl create -f pod.yaml
Result:
pod/pod created