Mounting a volume in Block mode
To mount a volume in volumeMode: Block
mode:
Before you start, install kubectl
Create a PersistentVolumeClaim object
-
To create a volume in block mode, set the
spec.volumeMode
field toBlock
.Save the following PersistentVolumeClaim creation specification to a YAML file named
pvc-block.yaml
.Note
If the
storageClassName
parameter is not specified, the default storage class (yc-network-hdd
) is used. To change the default class, see Change the default storage class.To learn more about the
PersistentVolumeClaim
creation specification, see the Kubernetes documentation .apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-block spec: accessModes: - ReadWriteOnce volumeMode: Block storageClassName: "yc-network-hdd" resources: requests: storage: 1Gi
-
Create the
PersistentVolumeClaim
object: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 this command:
kubectl create -f pod.yaml
Result:
pod/pod created