# Static volume provisioning


Create a [pod](../../concepts/index.md#pod) with a statically provisioned [volume](../../concepts/volume.md):
1. [Create a PersistentVolume](#create-pv).
1. [Create a PersistentVolumeClaim](#create-claim).
1. [Create a pod](#create-pod).

{% note tip %}

You can use a Yandex Object Storage [bucket](../../../storage/concepts/bucket.md) to store your pod. For more information, see [Integration with Object Storage](s3-csi-integration.md).

{% endnote %}

## Getting started {#before-you-begin}

1. [Install kubect](https://kubernetes.io/docs/tasks/tools/install-kubectl) and [configure it to work with the new cluster](../connect/index.md#kubectl-connect).

1. Find out the unique ID of the [disk](../../../compute/concepts/disk.md) you are going to use to create a `PersistentVolume`:
   1. If you do not have a disk yet, [create one](../../../compute/operations/disk-create/empty.md).

      {% note warning %}

      Make sure the disk is located in the same [availability zone](../../../overview/concepts/geo-scope.md) as the [nodes of the group](../../concepts/index.md#node-group) the pods will be running on.

      {% endnote %}

   1. Get the disk ID (the `ID` column):

      ```bash
      yc compute disk list
      ```

      Result:

      ```text
      +----------------------+------+------------+-------------------+--------+--------------+-------------+
      |          ID          | NAME |    SIZE    |       ZONE        | STATUS | INSTANCE IDS | DESCRIPTION |
      +----------------------+------+------------+-------------------+--------+--------------+-------------+
      | ef3ouo4sgl86******** | k8s  | 4294967296 | ru-central1-a     | READY  |              |             |
      +----------------------+------+------------+-------------------+--------+--------------+-------------+
      ```

1. Check the available [storage classes](manage-storage-class.md) and select the one you need:

   ```bash
   kubectl get storageclass
   ```

   Result:

   ```text
   NAME                          PROVISIONER                    RECLAIMPOLICY  VOLUMEBINDINGMODE     ALLOWVOLUMEEXPANSION  AGE
   yc-network-hdd (default)      disk-csi-driver.mks.ycloud.io  Delete         WaitForFirstConsumer  true                  12d
   yc-network-nvme               disk-csi-driver.mks.ycloud.io  Delete         WaitForFirstConsumer  true                  12d
   yc-network-ssd                disk-csi-driver.mks.ycloud.io  Delete         WaitForFirstConsumer  true                  12d
   yc-network-ssd-nonreplicated  disk-csi-driver.mks.ycloud.io  Delete         WaitForFirstConsumer  true                  12d
   ```

   {% note info %}

   Please note that [Kubernetes storage classes](manage-storage-class.md) and [Yandex Compute Cloud disk types](../../../compute/concepts/disk.md#disks_types) are different concepts.

   {% endnote %}

## Create a PersistentVolume {#create-pv}

1. Save the `PersistentVolume` creation specification to a YAML file named `test-pv.yaml`.

   For more information about the specification, see [this Kubernetes guide](https://kubernetes.io/docs/reference/kubernetes-api/config-and-storage-resources/persistent-volume-v1/).

   When providing the `spec.capacity.storage` parameter, make sure the exact disk size is specified. Container Storage Interface does not verify the disk size for statically provisioned volumes.

   To create a `PersistentVolume` from an existing cloud drive, enter its unique ID in the `volumeHandle` parameter.

   {% 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: PersistentVolume
   metadata:
     name: <PersistentVolume_name>
   spec:
     capacity:
       storage: <PersistentVolume_size>
     accessModes:
       - ReadWriteOnce
     csi:
       driver: disk-csi-driver.mks.ycloud.io
       fsType: ext4
       volumeHandle: <disk_ID>
     storageClassName: <storage_class_name>
   ```

1. Run this command:

   ```bash
   kubectl create -f test-pv.yaml
   ```

   Result:

   ```text
   persistentvolume/<PersistentVolume_name> created
   ```

1. View the information about the new `PersistentVolume`:

   ```bash
   kubectl describe persistentvolume <PersistentVolume_name>
   ```

   Result:

   ```text
   Name:            <PersistentVolume_name>
   Labels:          <none>
   Annotations:     <none>
   Finalizers:      [kubernetes.io/pv-protection]
   StorageClass:    <storage_class_name>
   Status:          Available
   ...
   ```

## Create a PersistentVolumeClaim {#create-claim}

1. Save the `PersistentVolumeClaim` creation specification to a YAML file named `test-claim.yaml`.

   For more information about the specification, see [this Kubernetes guide](https://kubernetes.io/docs/reference/kubernetes-api/config-and-storage-resources/persistent-volume-claim-v1/).

   ```yaml
   apiVersion: v1
   kind: PersistentVolumeClaim
   metadata:
     name: <PersistentVolumeClaim_name>
   spec:
     accessModes:
       - ReadWriteOnce
     resources:
       requests:
         storage: <PersistentVolumeClaim_size>
     storageClassName: <storage_class_name>
     volumeName: <PersistentVolume_name>
   ```

   {% note info %}

   The size of a `PersistentVolumeClaim` must be less than or equal to that of a `PersistentVolume`.

   {% endnote %}

1. Run this command:

   ```bash
   kubectl create -f test-claim.yaml
   ```

   Result:

   ```text
   persistentvolumeclaim/<PersistentVolumeClaim_name> created
   ```

1. View the information about the new `PersistentVolumeClaim`:

   ```bash
   kubectl describe persistentvolumeclaim <PersistentVolumeClaim_name>
   ```

   Result:

   ```text
   Name:          <PersistentVolumeClaim_name>
   Namespace:     default
   StorageClass:  <storage_class_name>
   Status:        Bound
   Volume:        <PersistentVolume_name>
   ...
   ```

## Create a pod with a statically provisioned volume {#create-pod}

1. Create a file named `test-pod.yaml` with a manifest for the pod using `PersistentVolumeClaim`:

   ```yaml
   apiVersion: v1
   kind: Pod
   metadata:
     name: test-pod
   spec:
     containers:
     - name: app
       image: ubuntu
       command: ["/bin/sh"]
       args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"]
       volumeMounts:
       - name: persistent-storage
         mountPath: /data
     volumes:
     - name: persistent-storage
       persistentVolumeClaim:
         claimName: <PersistentVolumeClaim_name>
   ```

   For more information about the specification, see [this Kubernetes guide](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/).
1. Run this command:

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

   Result:

   ```text
   pod/test-pod created
   ```

1. View the information about the new pod:

   ```bash
   kubectl describe pod test-pod
   ```

   Result:

   ```text
   Name:       test-pod
   Namespace:  default
   Priority:   0
   ...
     ----    ------                  ----  ----                     -------
     Normal  Scheduled               20m   default-scheduler        Successfully assigned default/test-pod to cl1jtehftl7q********-icut
     Normal  SuccessfulAttachVolume  20m   attachdetach-controller  AttachVolume.Attach succeeded for volume "<PersistentVolume_name>"
   ```

In the **Compute Cloud** management console under **Disks**, the word **Active** will appear next to your disk.

## How to delete a volume {#delete-volume}

Before deleting a volume, you must delete the pod that is using it. Disks in Compute Cloud are automatically deleted when you delete a `PersistentVolume` only if that `PersistentVolume` uses the `persistentVolumeReclaimPolicy: Delete` policy. To delete a volume completely:
1. Delete the pod:

   ```bash
   kubectl delete pod <pod_name>
   ```

1. Delete the `PersistentVolumeClaim` object:

   ```bash
   kubectl delete pvc <PersistentVolumeClaim_name>
   ```

1. Delete the `PersistentVolume` object:

   ```bash
   kubectl delete pv <PersistentVolume_name>
   ```

1. In Compute Cloud, [delete the disk](../../../compute/operations/disk-control/delete.md) associated with the `PersistentVolume`.

### See also {#see-also}

* [Volume](../../concepts/volume.md)
* [Using encrypted disks for persistent volumes](encrypted-disks.md)
* [Dynamic volume provisioning](dynamic-create-pv.md)
* [Managing storage classes](manage-storage-class.md)