[Yandex Cloud documentation](../../index.md) > [Yandex Data Processing](../index.md) > [Tutorials](index.md) > Integrating Yandex Data Processing with other services > Object Storage > Mounting buckets to Yandex Data Processing host filesystems

# Mounting Yandex Object Storage buckets to the file system of Yandex Data Processing hosts

# Mounting Yandex Object Storage buckets to the file system of Yandex Data Processing hosts


In Yandex Data Processing, you can use [initialization actions](../concepts/init-action.md) to configure hosts.

With these actions, you can automate the installation and setup of [GeeseFS](../../storage/tools/geesefs.md), the software enabling Yandex Data Processing cluster hosts to mount Yandex Object Storage buckets via [FUSE](https://en.wikipedia.org/wiki/Filesystem_in_Userspace).

To set up GeeseFS:

1. [Prepare the initialization action](#prepare-init-scripts).
1. [Create a cluster that uses the initialization action](#create-cluster).
1. [Check bucket availability](#check-availability).

If you no longer need the resources you created, [delete them](#clear-out).


## Required paid resources {#paid-resources}

The support cost for this solution includes:

* Fee for a Yandex Data Processing cluster (see [Yandex Data Processing pricing](../pricing.md)).
* Fee for a NAT gateway (see [Virtual Private Cloud pricing](../../vpc/pricing.md)).
* Object Storage bucket fee: data storage and data operations (see [Object Storage pricing](../../storage/pricing.md)).
* Fee for public IP addresses for cluster hosts (see [Virtual Private Cloud pricing](../../vpc/pricing.md)).


## Getting started {#before-you-begin}

Set up your infrastructure:

{% list tabs group=instructions %}

- Manually {#manual}

  1. [Create a service account](../../iam/operations/sa/create.md) with the `dataproc.agent` and `dataproc.provisioner` roles.

  1. [Create an Object Storage bucket](../../storage/operations/buckets/create.md).

  1. Grant the service account read access to the bucket by using one of the following methods:

      * [Set up the bucket ACL](../../storage/operations/buckets/edit-acl.md) and grant `READ` permission to the service account.

          The service account will get read access only to the specified bucket.

      * [Assign the service account](../../iam/operations/sa/assign-role-for-sa.md) the `storage.viewer` role.

          The service account will get read access to all buckets in the folder.

  1. Create a [NAT gateway](../../vpc/operations/create-nat-gateway.md) for the subnet you want to create your Yandex Data Processing cluster in.

- Terraform {#tf}

  1. If you do not have Terraform yet, [install it](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  1. [Get the authentication credentials](../../tutorials/infrastructure-management/terraform-quickstart.md#get-credentials). You can add them to environment variables or specify them later in the provider configuration file.
  1. [Configure and initialize a provider](../../tutorials/infrastructure-management/terraform-quickstart.md#configure-provider). There is no need to create a provider configuration file manually, you can [download it](https://github.com/yandex-cloud-examples/yc-terraform-provider-settings/blob/main/provider.tf).
  1. Place the configuration file in a separate working directory and [specify the parameter values](../../tutorials/infrastructure-management/terraform-quickstart.md#configure-provider). If you did not add the authentication credentials to environment variables, specify them in the configuration file.

  1. Download the [data-processing-init-actions-geesefs.tf](https://github.com/yandex-cloud-examples/yc-data-processing-init-actions/blob/main/data-processing-init-actions-geesefs.tf) configuration file to the same working directory.

      This file describes:

      * [Network](../../vpc/concepts/network.md#network).
      * [Subnet](../../vpc/concepts/network.md#subnet).
      * [Route table](../../vpc/concepts/routing.md#rt-vpc).
      * [NAT gateway](../../vpc/concepts/gateways.md).
      * [Security group](../../vpc/concepts/security-groups.md) and rules required to connect to the Yandex Data Processing cluster.
      * [Service account](../../iam/concepts/users/service-accounts.md) with the roles required to work with the Object Storage bucket and Yandex Data Processing cluster.
      * [Static key](../../iam/concepts/authorization/access-key.md) for the service account to manage the Object Storage bucket.
      * [Object Storage bucket](../../storage/concepts/bucket.md).
      * [Yandex Data Processing cluster](../concepts/index.md).

  1. In the `data-processing-init-actions-geesefs.tf` file, specify the following settings:

      * `dp_network_name`: Name of the network for your Yandex Data Processing cluster.
      * `dp_subnet_name`: Name of the subnet for your Yandex Data Processing cluster.
      * `dp_sg_name`: Name of the security group for your Yandex Data Processing cluster.
      * `dp_sa_folder_id`: ID of the folder to create your infrastructure and Yandex Data Processing cluster in.
      * `dp_sa_name`: Name of the service account for your Yandex Data Processing cluster and Object Storage bucket.
      * `dp_bucket_name`: Object Storage bucket name.
      * `dataproc_name`: Yandex Data Processing cluster name.
      * `ssh-path`: Path to the public SSH key file for your Yandex Data Processing cluster.

  1. Validate your Terraform configuration files using this command:

      ```bash
      terraform validate
      ```

      Terraform will display any configuration errors detected in your files.

  1. Create the required infrastructure:

      1. Run this command to view the planned changes:
      
         ```bash
         terraform plan
         ```
      
         If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
      
      1. If everything looks correct, apply the changes:
         1. Run this command:
      
            ```bash
            terraform apply
            ```
      
         1. Confirm updating the resources.
         1. Wait for the operation to complete.

      All the required resources will be created in the specified folder. You can check resource availability and their settings in the [management console](https://console.yandex.cloud).

{% endlist %}

## Prepare the initialization action {#prepare-init-scripts}

1. Create an initialization action file named `geesefs_mount.sh` taking two positional arguments: the name of the Object Storage bucket and the host's file system directory where you are going to mount it.

    ```bash
    #!/bin/bash

    set -e

    BUCKET=$1
    MOUNT_POINT=$2

    # Downloading GeeseFS
    wget https://github.com/yandex-cloud/geesefs/releases/latest/download/geesefs-linux-amd64 -O /opt/geesefs
    chmod a+rwx /opt/geesefs
    mkdir -p "${MOUNT_POINT}"

    # Preparing a script to run on every boot
    BOOT_SCRIPT="/var/lib/cloud/scripts/per-boot/80-geesefs-mount.sh"
    echo "#!/bin/bash" >> ${BOOT_SCRIPT}
    echo "/opt/geesefs -o allow_other --iam ${BUCKET} ${MOUNT_POINT}" >> ${BOOT_SCRIPT}
    chmod 755 ${BOOT_SCRIPT}

    # Running the script
    ${BOOT_SCRIPT}
    ```

1. [Upload](../../storage/operations/objects/upload.md) the `geesefs_mount.sh` file to the Object Storage bucket you created earlier.

## Create a cluster that will use the initialization action {#create-cluster}

{% list tabs group=instructions %}

- Manually {#manual}

  [Create a Yandex Data Processing cluster](../operations/cluster-create.md) with the following settings:

  * In the **Version** field, select `2.0`.
  * In the **Service account** field, select the service account you [previously created](#before-you-begin).
  * In the **Custom scripts** field, click **Add** and set the action parameters:

      * In the **URI** field, specify the path to the action file in the bucket, such as:

          ```http
          s3a://<bucket_name>/geesefs_mount.sh
          ```

      * In the **Arguments** field, specify the name of the [previously created](#before-you-begin) bucket and `/mnt/test` as your mount point. Specify arguments on separate lines:

          ```text
          <bucket_name>
          /mnt/test
          ```

  * In the **Bucket name** field, select the [previously created](#before-you-begin) bucket.

  * In the **Subclusters** menu, enable **Public access** in the settings

      {% note info %}
      
      Public access to cluster hosts is required if you plan to connect to the cluster via the internet. This connection option is simpler and is recommended for the purposes of this guide. You can connect to non-public hosts as well but only from Yandex Cloud virtual machines located in the same cloud network as the cluster.
      
      {% endnote %}

- Terraform {#tf}

  1. In the `data-processing-init-actions-geesefs.tf` file, set the variable value as follows: `create_cluster` = `1`.

  1. Validate your Terraform configuration files using this command:

      ```bash
      terraform validate
      ```

      Terraform will display any configuration errors detected in your files.

  1. Create the required infrastructure:

      1. Run this command to view the planned changes:
      
         ```bash
         terraform plan
         ```
      
         If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
      
      1. If everything looks correct, apply the changes:
         1. Run this command:
      
            ```bash
            terraform apply
            ```
      
         1. Confirm updating the resources.
         1. Wait for the operation to complete.

      All the required resources will be created in the specified folder. You can check resource availability and their settings in the [management console](https://console.yandex.cloud).

{% endlist %}

## Check bucket availability {#check-availability}

1. After the cluster status changes to **Alive**, [connect](../operations/connect-ssh.md) over SSH to any of its hosts as the `ubuntu` user.

1. To make sure the bucket has been mounted successfully, run this command:

    ```bash
    ls /mnt/test
    ```

    It will output the list of objects stored in the bucket’s root folder. In this case, the name of the `geesefs_mount.sh` file.

## Delete the resources you created {#clear-out}

{% note tip %}

Before deleting the infrastructure, manually delete all objects from the bucket.

{% endnote %}

Delete the resources you no longer need to avoid paying for them:

{% list tabs group=instructions %}

- Manually {#manual}

  1. [Delete the Yandex Data Processing cluster](../operations/cluster-delete.md).
  1. If you used static public IP addresses to access the cluster hosts, release and [delete them](../../vpc/operations/address-delete.md).
  1. [Delete the Object Storage bucket](../../storage/operations/buckets/delete.md).
  1. [Delete the service account](../../iam/operations/sa/delete.md).

- Terraform {#tf}

  1. In the terminal, navigate to the working directory with the `data-processing-init-actions-geesefs.tf` configuration file.
  1. Delete the resources using this command:

      ```bash
      terraform destroy
      ```

  1. Type `yes` and press **Enter**.

      This will delete all resources described in the `data-processing-init-actions-geesefs.tf` configuration file.

{% endlist %}