Static volume provisioning
Create a pod with a statically provisioned volume:
Tip
You can use a Yandex Object Storage bucket to store your pod. For more information, see Integration with Object Storage.
Getting started
-
Install kubect
and configure it to work with the new cluster. -
Find out the unique ID of the disk you are going to use to create a
PersistentVolume:-
If you do not have a disk yet, create one.
Warning
Make sure the disk is located in the same availability zone as the nodes of the group the pods will be running on.
-
Get the disk ID (the
IDcolumn):yc compute disk listResult:
+----------------------+------+------------+-------------------+--------+--------------+-------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | DESCRIPTION | +----------------------+------+------------+-------------------+--------+--------------+-------------+ | ef3ouo4sgl86******** | k8s | 4294967296 | ru-central1-a | READY | | | +----------------------+------+------------+-------------------+--------+--------------+-------------+
-
-
Check the available storage classes and select the one you need:
kubectl get storageclassResult:
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 12dNote
Please note that Kubernetes storage classes and Yandex Compute Cloud disk types are different concepts.
Create a PersistentVolume
-
Save the
PersistentVolumecreation specification to a YAML file namedtest-pv.yaml.For more information about the specification, see this Kubernetes guide
.When providing the
spec.capacity.storageparameter, make sure the exact disk size is specified. Container Storage Interface does not verify the disk size for statically provisioned volumes.To create a
PersistentVolumefrom an existing cloud drive, enter its unique ID in thevolumeHandleparameter.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: 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> -
Run this command:
kubectl create -f test-pv.yamlResult:
persistentvolume/<PersistentVolume_name> created -
View the information about the new
PersistentVolume:kubectl describe persistentvolume <PersistentVolume_name>Result:
Name: <PersistentVolume_name> Labels: <none> Annotations: <none> Finalizers: [kubernetes.io/pv-protection] StorageClass: <storage_class_name> Status: Available ...
Create a PersistentVolumeClaim
-
Save the
PersistentVolumeClaimcreation specification to a YAML file namedtest-claim.yaml.For more information about the specification, see this Kubernetes guide
.apiVersion: v1 kind: PersistentVolumeClaim metadata: name: <PersistentVolumeClaim_name> spec: accessModes: - ReadWriteOnce resources: requests: storage: <PersistentVolumeClaim_size> storageClassName: <storage_class_name> volumeName: <PersistentVolume_name>Note
The size of a
PersistentVolumeClaimmust be less than or equal to that of aPersistentVolume. -
Run this command:
kubectl create -f test-claim.yamlResult:
persistentvolumeclaim/<PersistentVolumeClaim_name> created -
View the information about the new
PersistentVolumeClaim:kubectl describe persistentvolumeclaim <PersistentVolumeClaim_name>Result:
Name: <PersistentVolumeClaim_name> Namespace: default StorageClass: <storage_class_name> Status: Bound Volume: <PersistentVolume_name> ...
Create a pod with a statically provisioned volume
-
Create a file named
test-pod.yamlwith a manifest for the pod usingPersistentVolumeClaim: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
. -
Run this command:
kubectl create -f test-pod.yamlResult:
pod/test-pod created -
View the information about the new pod:
kubectl describe pod test-podResult:
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
Disks are not deleted automatically from Compute Cloud when you delete a PersistentVolume. To delete a volume completely:
-
Delete the
PersistentVolumeClaim:kubectl delete pvc <PersistentVolumeClaim_ID> -
Delete the
PersistentVolume:kubectl delete pv <PersistentVolume_ID> -
In Compute Cloud, delete the disk associated with the
PersistentVolume.