> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nebius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Mounting shared filesystems to pods in a Managed Service for Kubernetes® cluster

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](./disk-over-csi).

## Costs

The tutorial includes the following chargeable resources:

* [Compute shared filesystem](../../compute/resources/pricing#shared-filesystems)
* [Compute virtual machines](../../compute/resources/pricing) that make up a node group

## Prerequisites

1. Make sure you are in a [group](/iam/authorization/groups/index) that has at least the `editor` role within your tenant; for example, the default `editors` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.

2. [Install](../../cli/install) and [configure](../../cli/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](https://kubernetes.io/docs/tasks/tools/#kubectl) and [Helm](https://helm.sh/docs/intro/install/).

4. Install `jq`:

   <CodeGroup>
     ```bash Ubuntu theme={null}
     sudo apt-get install jq
     ```

     ```bash macOS theme={null}
     brew install jq
     ```
   </CodeGroup>

5. [Create a Managed Service for Kubernetes cluster](../clusters/manage) or choose an existing one, and save its ID to the `K8S_CLUSTER_ID` environment variable:

   ```bash theme={null}
   export K8S_CLUSTER_ID=$(nebius mk8s cluster get-by-name \
     --name <cluster_name> --format json | jq -r '.metadata.id')
   ```

## Steps

### Create a shared filesystem

<Warning>
  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](/iam/overview).
</Warning>

This command creates an 256 GiB SSD shared filesystem:

```bash theme={null}
export 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:

   ```bash theme={null}
   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.

   <Danger>
     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.
   </Danger>

2. Create the partial specification of the node template (other template fields will be set as the Nebius AI Cloud CLI parameters):

   ```bash theme={null}
   export K8S_NODE_TEMPLATE=$(cat <<EOF
   {
     "spec": {
       "template": {
         "filesystems": [
           {
             "attach_mode": "READ_WRITE",
             "mount_tag": "$MOUNT_TAG",
             "existing_filesystem": {
               "id": "$FS_ID"
             }
           }
         ],
         "cloud_init_user_data": $USER_DATA
       }
     }
   }
   EOF
   )
   ```

3. Create the node group:

   ```bash theme={null}
   nebius mk8s node-group create \
     --parent-id $K8S_CLUSTER_ID \
     --name "ng-1" \
     --fixed-node-count 2 \
     --template-resources-platform "cpu-e2" \
     --template-resources-preset "2vcpu-8gb" \
     "$K8S_NODE_TEMPLATE"
   ```

### Install the CSI driver

1. Pull the driver's Helm chart:

   ```bash theme={null}
   helm pull \
     oci://cr.eu-north1.nebius.cloud/mk8s/helm/csi-mounted-fs-path \
     --version 0.1.5
   ```

2. Install the chart:

   ```bash theme={null}
   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`:

```yaml theme={null}
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:

   <Tabs group="interfaces">
     <Tab title="Web console">
       1. In the sidebar, go to <Icon icon="https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/sidebar/compute.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=b91340217b08a1456d88ae0347f281d1" width="16" height="16" data-path="_assets/sidebar/compute.svg" /> **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 <Icon icon="https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/button-vellipsis.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=e80b8e57c43bfd117679262e6a1334ad" width="12" height="24" data-path="_assets/button-vellipsis.svg" /> → **Delete**.
       4. Confirm the node group deletion.
     </Tab>

     <Tab title="CLI">
       1. Get the ID of the node group that you want to delete:

          ```bash theme={null}
          nebius mk8s node-group list --parent-id <cluster_ID>
          ```

       2. Delete the node group:

          ```bash theme={null}
          nebius mk8s node-group delete --id <node_group_ID>
          ```
     </Tab>
   </Tabs>

2. Delete the Compute shared filesystem:

   <Tabs group="interfaces">
     <Tab title="Web console">
       1. In the sidebar, go to <Icon icon="https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/sidebar/storage.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=0a2dad6b48aea10e85f6f3e2343aee26" width="16" height="16" data-path="_assets/sidebar/storage.svg" /> **Storage** → **Shared filesystems**.
       2. Next to the filesystem's name, click <Icon icon="https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/button-vellipsis.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=e80b8e57c43bfd117679262e6a1334ad" width="12" height="24" data-path="_assets/button-vellipsis.svg" /> → **Delete**.
       3. Enter the filesystem's name and confirm deletion.
     </Tab>

     <Tab title="CLI">
       ```bash theme={null}
       nebius compute filesystem delete --id \
         $(nebius compute filesystem get-by-name \
           --name=<filesystem_name> \
           --format json \
           | jq -r ".metadata.id")
       ```
     </Tab>
   </Tabs>

## See also

* [Mounting disks to pods in a Managed Service for Kubernetes® cluster](./disk-over-csi)
* [Types of storage volumes in Compute](../../compute/storage/types)
