Static volume provisioning
Create a pod with a statically provisioned volume:
Tip
You can use a Object Storage bucket as storage for the pod. For more information, see Integration with Object Storage.
Before you begin
-
Install kubectl
and configure it to work with the created cluster. -
Look up the unique ID of the disk to be used to create a
PersistentVolume
:-
If you don't have a disk yet, create one.
-
Get the disk ID (the
ID
column):ncp compute disk list
Result:
+----------------------+------+------------+-------------------+--------+--------------+-------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | DESCRIPTION | +----------------------+------+------------+-------------------+--------+--------------+-------------+ | ef3ouo4sgl86740ridn6 | k8s | 4294967296 | eu-north1-c | READY | | | +----------------------+------+------------+-------------------+--------+--------------+-------------+
-
-
Check what storage classes are available and select the appropriate one:
kubectl get storageclass
Result:
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE nebius-network-ssd nebius.com Delete WaitForFirstConsumer true 12d
Note
Please note that Kubernetes storage classes and Compute Cloud disk types are different concepts.
Create a PersistentVolume object
-
Save the specification you used to create your
PersistentVolume
to a YAML file namedtest-pv.yaml
.For more information about the specification, see the Kubernetes documentation
.When setting the
spec.capacity.storage
parameter, make sure you specified the exact size of the disk. Container Storage Interface doesn't validate the disk size for statically prepared volumes.To create a
PersistentVolume
from an existing cloud drive, enter its unique disk ID in thevolumeHandle
parameter.To learn more about the
PersistentVolumeClaim
creation specification, see the Kubernetes documentation . -
Run the following command:
kubectl create -f test-pv.yaml
Result:
persistentvolume/<PersistentVolume name> created
-
View information about the created
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 object
-
Save the
PersistentVolumeClaim
creation specification to a YAML file namedtest-claim.yaml
.For more information about the specification, see the Kubernetes documentation
.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
PersistentVolumeClaim
must be less than or equal to that ofPersistentVolume
.-
Run the following command:
kubectl create -f test-claim.yaml
Result:
persistentvolumeclaim/<PersistentVolumeClaim name> created
-
View information about the
PersistentVolumeClaim
created: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.yaml
with a manifest of a pod that usesPersistentVolumeClaim
: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 the Kubernetes documentation
. -
Run the following command:
kubectl create -f test-pod.yaml
Result:
pod/test-pod created
-
View information about the pod created:
kubectl describe pod test-pod
Result:
Name: test-pod Namespace: default Priority: 0 ... ---- ------ ---- ---- ------- Normal Scheduled 20m default-scheduler Successfully assigned default/test-pod to cl1jtehftl7q1umj18ll-icut Normal SuccessfulAttachVolume 20m attachdetach-controller AttachVolume.Attach succeeded for volume "<PersistentVolume name>"
In the Compute Cloud management console under Disks, you will see the word Active next to the disk you're using.
How to delete a volume
Disks aren't deleted automatically from Compute Cloud when you delete PersistentVolume
. To delete the volume completely:
-
Delete the
PersistentVolumeClaim
object:kubectl delete pvc <PersistentVolumeClaim object ID>
-
Delete the
PersistentVolume
object:kubectl delete pv <PersistentVolume object ID>
-
Delete the disk in Compute Cloud that is linked to the
PersistentVolume
object.