# Mounting a volume in block mode


To mount a [volume](../../concepts/volume.md#block) in `volumeMode: Block` mode:
1. [Create a PersistentVolumeClaim](#create-pvc).
1. [Create a pod with the mounted volume](#create-pod).

First, [install kubectl](https://kubernetes.io/ru/docs/tasks/tools/install-kubectl/) and [configure it to work with the Managed Service for Kubernetes cluster you created](../connect/index.md#kubectl-connect).

## Create a PersistentVolumeClaim {#create-pvc}

1. To create a volume in block mode, set the `spec.volumeMode` field to `Block`.

   Save the following [PersistentVolumeClaim](dynamic-create-pv.md) creation specification to a YAML file named `pvc-block.yaml`.

   {% note info %}

   If the `storageClassName` parameter 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](manage-storage-class.md#sc-default).

   {% endnote %}

   Learn more about the `PersistentVolumeClaim` creation specification in the [Kubernetes guide](https://kubernetes.io/docs/reference/kubernetes-api/config-and-storage-resources/persistent-volume-claim-v1/).

   ```yaml
   apiVersion: v1
   kind: PersistentVolumeClaim
   metadata:
     name: pvc-block
   spec:
     accessModes:
       - ReadWriteOnce
     volumeMode: Block
     storageClassName: "yc-network-hdd"
     resources:
       requests:
         storage: 1Gi
   ```

1. Create a `PersistentVolumeClaim`:

   ```bash
   kubectl create -f pvc-block.yaml
   ```

   Result:

   ```bash
   persistentvolumeclaim/pvc-block created
   ```

## Create a pod with the mounted volume {#create-pod}

1. 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`.

   Learn more about the pod creation specification in [this Kubernetes guide](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#pod-v1-core).

   ```yaml
   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
   ```

1. Run this command:

   ```bash
   kubectl create -f pod.yaml
   ```

   Result:

   ```bash
   pod/pod created
   ```