Background
By default, files created or modified by a container in a Kubernetes pod are lost when the container crashes, or is stopped or restarted. Persistent volumes help you avoid this: they keep the files for the lifetime of the pod, regardless of the states of its individual containers to the pod. These volumes are mounted to a node that is running the pod. In Nebius AI Cloud, Managed Service for Kubernetes offers a native solution for persistent volumes in your clusters. You can mount disks from another Nebius AI Cloud service, Compute, to your pods as persistent volumes. Compute provides multiple disk types that vary in performance, reliability and price, and you can choose between them depending on your use case. For more details, see the Compute documentation. Mounting disks to pods relies on support for Container Storage Interface (CSI), which is enabled on newer Managed Kubernetes clusters and can be enabled for older clusters (see prerequisites below). A disk can be used on one node at a time. If you need to share data between pods and nodes, use Compute shared filesystems instead of disks. See Mounting shared filesystems to pods in a Managed Service for Kubernetes® cluster for details.Costs
Nebius AI Cloud only charges for a Compute disk. For more details, see the Compute pricing.Prerequisites
- Create a Managed Kubernetes cluster or choose an existing one.
- If you are working with an existing cluster, verify that it supports CSI.
- Install kubectl and connect to the cluster.
Verify that your cluster supports CSI
If your Managed Kubernetes cluster was created on or after January 7, 2025, it already supports CSI and no additional configuration is required. Proceed to the tutorial’s steps. If your cluster was created before January 7, 2025, enable CSI support in it:How to enable CSI support
How to enable CSI support
-
Get IDs of the node groups in the cluster:
- Web console
- CLI
- In Managed Kubernetes, click on your cluster.
- Switch to the Node groups tab.
- For each node group, find its ID under its name and click
to copy it.
-
Upgrade each node group:
- Contact support or your solution architect to enable CSI support.
Steps
Create a storage class for custom provisioning (optional)
Before using Compute disks as persistent volumes, you can choose how disks are provisioned: the disk type, the filesystem type (ext4 or xfs) and when a disk should be created (together with a persistent volume claim or when the claim is used by a pod). To do this, define a custom Kubernetes storage class.The default storage class offered by Managed Kubernetes,
compute-csi-default-sc, creates a Network SSD disk with an ext4 filesystem, and does so when a pod that uses a persistent volume claim with this storage class is created. If this configuration suits you, you can skip this step and proceed to creating a persistent volume claim.-
Create a manifest, e.g.,
storage-class.yaml, that defines the storage class. For example:-
.metadata.name— The name of the storage class. Use it when referring to the class in persistent volume claims (.spec.storageClassName). -
.provisioner— The volume provisioner. For Nebius AI Cloud disks, the provisioner iscompute.csi.nebius.com. -
.volumeBindingMode— The volume binding mode that determines when a Nebius AI Cloud disk is created for a persistent volume claim of this storage class. Supported values areWaitForFirstCustomer(the disk is created together with a pod that uses the claim) orImmediate(the disk is created together with the claim, even if no pods use it yet). -
.parameters."csi.storage.k8s.io/fstype"— The filesystem for disks:ext4orxfs. -
.parameters.type— The Nebius AI Cloud disk type. See the list of disk types and their IDs. Write IDs in uppercase, for example,NETWORK_SSD,NETWORK_SSD_IO_M3.
-
-
Apply the manifest to your cluster:
Create a persistent volume claim
Persistent volume claims are requests that pods make for persistent volumes. These requests include what kind of storage should be provided (in our case, a Compute disk with the default or a custom storage class) and how large it should be. To create a persistent volume claim:-
Create a manifest, e.g.,
pvc.yaml, that defines the claim. For example:.metadata.name— The name of your claim. Use it when referring to the claim in pod configurations..spec.accessModes— An array of access modes that determine how the persistent volume can be mounted to nodes. The only mode supported for Nebius AI Cloud block storage isReadWriteOnce; the volume can be mounted as read-write by a single node. For storage that can be mounted to multiple nodes (ReadWriteMany), see Mounting shared filesystems to pods in a Managed Service for Kubernetes® cluster..spec.storageClassName— The storage class of the volume. The default storage class for Nebius AI Cloud block storage,compute-csi-default-sc, creates a Network SSD disk with an ext4 filesystem. To use another disk type or filesystem, create a custom storage class by using the Nebius AI Cloud provisioner and specify its name here..spec.resources.requests.storage— The volume size.
-
Apply the manifest to your cluster:
Mount a volume to a pod and test it
When a persistent volume claim is used in a pod’s specification, the Compute disk created for the claim is mounted to the pod as a persistent volume. To create a pod with a volume and test it:-
Create a manifest, e.g.
pod.yaml, that defines the pod. For example, in the manifest below, a volume namedpersistent-storage, created from thetest-claimpersistent volume claim, is mounted to the pod’s container at/data:.spec.volumes[0].name: The name of the volume that is created for the pod..spec.volumes[0].persistentVolumeClaim.claimName: The name of the persistent volume claim that is used to create a volume..spec.containers[0].volumeMounts[0].name: The same volume name as in.spec.volumes[0].name..spec.containers[0].volumeMounts[0].mountPath: The mount point for the volume.
You can configure volumes in Kubernetes resources that manage pods, like deployments or stateful sets, in the same way, by using sub-fields of.spec.template.spec.volumesand.spec.template.spec.containers. -
Apply the manifest to your cluster:
-
Wait until the pod is ready:
-
Test that the container has written into
/data/out.txt: