Skip to main content
In this tutorial, you will use a Container Storage Interface (CSI) driver offered by Nebius AI Cloud to mount a Compute shared filesystem to nodes in a Managed Service for Kubernetes and use it as a persistent volume shared between pods running on the nodes. To work with disks that can be mounted to a single node instead of shared filesystems, see Mounting disks to pods in a Managed Service for Kubernetes® cluster.

Costs

The tutorial includes the following chargeable resources:

Prerequisites

  1. Make sure you are in a group that has at least the editor role within your tenant; for example, the default editors group. You can check this in the Administration → IAM section of the web console.
  2. Install and configure the Nebius AI Cloud CLI. The CLI commands in this article assume that the CLI is properly configured. For example, they omit the ID of the parent project, as it is assumed to be set in the CLI profile.
  3. Install kubectl and Helm.
  4. Install jq:
    sudo apt-get install jq
    
  5. Create a Managed Service for Kubernetes cluster or choose an existing one, and save its ID to the NB_K8S_CLUSTER_ID environment variable:
    export NB_K8S_CLUSTER_ID=$(nebius mk8s cluster get-by-name \
      --name <cluster_name> --format json | jq -r '.metadata.id')
    

Steps

Create a shared filesystem

The filesystem that you are adding to a node group must be located in the same project as the node group’s parent cluster. For more details about projects and resource hierarchy in Nebius AI Cloud, see How resources, identities and access are managed in Nebius AI Cloud.
This command creates an 256 GiB SSD shared filesystem:
export NB_FS_ID=$(nebius compute filesystem create \
  --name mk8s-csi-storage \
  --size-gibibytes 256 \
  --type network_ssd \
  --block-size-bytes 4096 \
  --format json | jq -r ".metadata.id")
When setting the filesystem size (size-gibibytes), make sure it is enough for all your pods to store their data.

Create a node group and mount the filesystem to nodes

  1. Create the cloud-init user data that will mount the shared filesystem to nodes:
    export MOUNT_POINT=/mnt/data
    export MOUNT_TAG=csi-storage
    export USER_DATA=$(jq -Rs '.' <<EOF
    runcmd:
      - sudo mkdir -p $MOUNT_POINT
      - sudo mount -t virtiofs $MOUNT_TAG $MOUNT_POINT
      - printf "%s %s virtiofs defaults,nofail 0 2\n" "$MOUNT_TAG" "$MOUNT_POINT" | sudo tee -a /etc/fstab
    EOF
    )
    
    This will mount the filesystem to nodes at /mnt/data as csi-storage. To use another mount point or mount tag, modify the variables.
    Do not omit nofail. If it is not specified and a node cannot find the filesystem on restart (for example, it has been deleted), the node will not boot.
  2. Create the partial specification of the node template (other template fields will be set as the Nebius AI Cloud CLI parameters):
    export NB_K8S_NODE_TEMPLATE=$(cat <<EOF
    {
      "spec": {
        "template": {
          "filesystems": [
            {
              "attach_mode": "READ_WRITE",
              "mount_tag": "$MOUNT_TAG",
              "existing_filesystem": {
                "id": "$NB_FS_ID"
              }
            }
          ],
          "cloud_init_user_data": $USER_DATA
        }
      }
    }
    EOF
    )
    
  3. Create the node group:
    nebius mk8s node-group create \
      --parent-id $NB_K8S_CLUSTER_ID \
      --name "ng-1" \
      --fixed-node-count 2 \
      --template-resources-platform "cpu-e2" \
      --template-resources-preset "2vcpu-8gb" \
      "$NB_K8S_NODE_TEMPLATE"
    

Install the CSI driver

  1. Pull the driver’s Helm chart:
    helm pull \
      oci://cr.eu-north1.nebius.cloud/mk8s/helm/csi-mounted-fs-path \
      --version 0.1.5
    
  2. Install the chart:
    helm upgrade csi-mounted-fs-path ./csi-mounted-fs-path-0.1.5.tgz --install \
      --set dataDir=$MOUNT_POINT/csi-mounted-fs-path-data/
    

Mount the filesystem to pods

Here is an example of a PersistentVolumeClaim that claims space on the shared filesystem, and a pod that mounts the filesystem at /data through the PersistentVolumeClaim:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: csi-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: csi-mounted-fs-path-sc
---
kind: Pod
apiVersion: v1
metadata:
  name: my-csi-app
spec:
  containers:
  - name: my-csi-app
    image: busybox
    volumeMounts:
      - mountPath: "/data"
        name: my-csi-volume
    command: [ "sleep", "1000000" ]
    securityContext:
      allowPrivilegeEscalation: false
      privileged: false
  volumes:
  - name: my-csi-volume
    persistentVolumeClaim:
      claimName: csi-pvc

How to delete the created resources

Some of the created resources are chargeable. If you do not need them, delete these resources, so Nebius AI Cloud does not charge for them:
  1. Delete the node group:
    1. In the sidebar, go to https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/sidebar/compute.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=b91340217b08a1456d88ae0347f281d1 Compute → Kubernetes.
    2. Open the page of the required cluster and then go to the Node groups tab.
    3. In the row of the required node group, click https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/button-vellipsis.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=e80b8e57c43bfd117679262e6a1334ad → Delete.
    4. Confirm the node group deletion.
  2. Delete the Compute shared filesystem:
    1. In the sidebar, go to https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/sidebar/storage.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=0a2dad6b48aea10e85f6f3e2343aee26 Storage → Shared filesystems.
    2. Next to the filesystem’s name, click https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/button-vellipsis.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=e80b8e57c43bfd117679262e6a1334adDelete.
    3. Enter the filesystem’s name and confirm deletion.

See also