Mounting a volume in block mode
To mount a volume in volumeMode: Block mode:
First, install kubectl
Create a PersistentVolumeClaim
-
To create a volume in block mode, set the
spec.volumeModefield toBlock.Save the following PersistentVolumeClaim creation specification to a YAML file named
pvc-block.yaml.Note
If the
storageClassNameparameter is not specified, the default storage class,yc-network-hdd, will be used. Learn how to change the default class in Update the default storage class.Learn more about the
PersistentVolumeClaimcreation specification in the Kubernetes guide .apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-block spec: accessModes: - ReadWriteOnce volumeMode: Block storageClassName: "yc-network-hdd" resources: requests: storage: 1Gi -
Create a
PersistentVolumeClaim:kubectl create -f pvc-block.yamlResult:
persistentvolumeclaim/pvc-block created
Create a pod with the mounted volume
-
When creating a volume pod in block mode, specify the
spec.containers.volumeDevicesfield.Save the following pod creation specification to a YAML file named
pod.yaml.Learn more about the pod creation specification in this Kubernetes guide
.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 this command:
kubectl create -f pod.yamlResult:
pod/pod created