[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for Valkey™](../index.md) > [Step-by-step guides](index.md) > Clusters > Creating a cluster

# Creating a Valkey™ cluster



A Valkey™ cluster consists of one or more database hosts, with the option to configure replication between them. Replication is enabled by default in any cluster with more than one host: the master host accepts write requests and propagates the changes to its replicas.

For more information on the Yandex Managed Service for Valkey™ cluster structure, see [Resource relationships](../concepts/index.md).

{% note info %}

* The number of hosts you can create together with a Valkey™ cluster depends on the selected [disk type](../concepts/storage.md#storage-type-selection) and [host class](../concepts/instance-types.md#available-flavors), as well as on whether [sharding](../concepts/sharding.md) is used.
* The available disk types [depend](../concepts/storage.md) on the selected [host class](../concepts/instance-types.md).

{% endnote %}



Cluster DB connections are managed by Connection Manager. Creating a cluster automatically creates:

* [Connection Manager connection](../../metadata-hub/concepts/connection-manager.md) with information about the database connection.

* [Yandex Lockbox secret](../../metadata-hub/concepts/secret.md) that stores the DB owner's user password. Storing passwords in Yandex Lockbox ensures their security.

The connection and secret will be created for each new database user. To view all connections, select the **Connections** tab on the cluster page.

You need the `connection-manager.viewer` role to view connection info. You can [use Connection Manager](../../metadata-hub/operations/connection-access.md) to configure access to connections.

You can use Connection Manager and secrets you create there free of charge.



## Creating a cluster {#create-cluster}


To create a Yandex Managed Service for Valkey™ cluster, you need the [vpc.user](../../vpc/security/index.md#vpc-user) role along with the [managed-redis.editor role or higher](../security/index.md#roles-list). To learn how to assign a role, see [this Identity and Access Management guide](../../iam/operations/roles/grant.md).


{% note info %}

The following restrictions apply when creating sharded clusters:

* You can create a single-shard cluster using the CLI, Terraform, or API.
* You cannot create a cluster with two shards, but you can [add a shard](shards.md#add) to an existing single-shard cluster.
* You can create a cluster with three or more shards using the management console, CLI, Terraform, or API.

There are no restrictions for non-sharded clusters.

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}


  To create a Yandex Managed Service for Valkey™ cluster:

  1. In the [management console](https://console.yandex.cloud), go to the folder where you want to create your database cluster.
  1. Navigate to **Yandex Managed Service for&nbsp;Valkey™**.
  1. Click **Create cluster**.
  1. Under **Basic parameters**:

     * Enter a name for the cluster in the **Cluster name** field. The cluster name must be unique within the folder.
     * Optionally, add a cluster description.
     * Select your cluster environment. Note that you cannot change the environment once the cluster is created:
       * `PRODUCTION`: For stable versions of your applications.
       * `PRESTABLE`: For testing purposes. The prestable environment is similar to the production environment and likewise covered by an SLA, but it is the first to get new features, improvements, and bug fixes. In the prestable environment, you can test new versions for compatibility with your application.
     * Select the DBMS version.
     * Optionally, add labels.
     * Enable [cluster sharding](../concepts/sharding.md), if required.

          {% note warning %}

          You cannot disable sharding in a cluster where it is already enabled. You can create a non-sharded cluster and [enable sharding](update.md#enable-sharding) later, if required.

          {% endnote %}

     * Enable encrypted TLS connections to your cluster, if required.

          {% note warning %}

          You can enable encrypted connections only when creating a new cluster. You cannot disable encryption for an existing cluster.

          {% endnote %}

     * Optionally, enable [using FQDNs instead of IP addresses](../concepts/network.md#fqdn-ip-setting).

        {% note info %}
        
        Some clients do not support this setting and will fail to connect to the cluster hosts. They expect an IP address and will produce errors if you provide an FQDN instead.
        
        {% endnote %}

     * Select the [data persistence](../concepts/replication.md#persistence) mode.

  1. Under **Resources**:

     * Select a platform in the **Platform** field.
     * Specify the **Type** of virtual machine where you want to deploy the hosts.
     * Select **Host class**.

     
     * Select the [disk type](../concepts/storage.md):
       * Either the more flexible network SSD (`network-ssd`) or non-replicated SSD (`network-ssd-nonreplicated`) storage
       * Or the faster local SSD (`local-ssd`) storage

       The type you select determines the increments for changing the disk size:
       
       * Network SSD storage: In increments of 1 GB.
       * Local SSDs:
           * For **Intel Broadwell** and **Intel Cascade Lake**: In 100 GB increments.
           * For **Intel Ice Lake** and **AMD Zen 4**: In 368 GB increments.
       * Non-replicated SSDs: In increments of 93 GB.


     * Select the storage size. The available storage size is capped by [quotas and limits](../concepts/limits.md#mrd-limits).

     * In the **Increase size** field, set the conditions for the actions below:
     
         * Storage expansion during the [next maintenance window](../concepts/maintenance.md#maintenance-window) if and when the specified storage space utilization percentage is exceeded. If you set this condition, configure the maintenance schedule.
     
         * Storage expansion immediately if and when the specified storage space utilization percentage is exceeded.
     
             {% note warning %}
     
             If you set both conditions, make sure the immediate expansion threshold is higher than the scheduled one.
     
             {% endnote %}
     
     * In the **Maximum storage size** field, specify the maximum storage size that can be set during autoscaling.
     
     
     {% note warning %}
     
     * You cannot decrease the storage size after automatic expansion.
     * During storage resizing, cluster hosts will be stopped and updated one at a time.
     
     {% endnote %}

     
     * Optionally, select **Encrypted disk** to encrypt the disk with a [custom KMS key](../../kms/concepts/key.md).

       * To [create](../../kms/operations/key.md#create) a new key, click **Create**.

       * To use a previously created key, select it in the **KMS key** field.

       To learn more about disk encryption, see [Storage](../concepts/storage.md#disk-encryption).


  
    1. Under **Network settings**, select:
       * [Cloud network](../../vpc/concepts/network.md#network) for cluster deployment.
       * Security groups for cluster network traffic. You may need to additionally [set up security groups](connect/index.md#configuring-security-groups) to be able connect to the cluster.


  1. Under **Hosts**, configure the hosts:

      * To change the settings of a host, click ![pencil](../../_assets/console-icons/pencil.svg) next to the host name.

          * **Availability zone**: Select the [availability zone](../../overview/concepts/geo-scope.md).

          
          * **Subnet**: Specify a [subnet](../../vpc/concepts/network.md#subnet) in the selected availability zone.
          * **Public access**: Enables access to the host from the internet if you enabled **TLS support** for the cluster.


          * **Master priority**: Host priority for promotion to master if the [primary master fails](../concepts/replication.md#master-failover).
          * **Shard name**: Enables you to change the shard name for the host. This field is only available if you enabled **Cluster sharding** for the cluster.

      * To add hosts to your cluster, click **Add host**.

      If you enabled cluster sharding and selected the **local-ssd** disk type, add at least two hosts per shard.

  1. Under **DBMS settings**:

      * In the **Password** field, enter the user password.

         The password must be from 8 to 128 characters long and match the `[a-zA-Z0-9@=+?*.,!&#$^<>_-]*` regular expression.

      * Configure the [DBMS settings](../concepts/settings-list.md), if required.

  1. Under **Service settings**, configure the additional cluster settings as follows:

      - **Backup start time (UTC)**: Cluster backup start time (UTC, 24-hour format). If you leave the time unset, the [backup](cluster-backups.md) will start at 22:00 UTC.
      
      - **Maintenance**: [Maintenance window](../concepts/maintenance.md) settings:
      
          * To enable maintenance at any time, select **At any time** (default).
          * To specify the preferred maintenance start time, select **By schedule** and specify the day of the week and the UTC time interval. For example, you can choose a time when the cluster is least loaded.
          
          Both active and stopped clusters are subject to maintenance. Maintenance operations include DBMS updates, patches, etc.
      
      - **Deletion protection**: Manages cluster protection against accidental deletion.
      
          Even with deletion protection enabled, one can still connect to the cluster manually and delete the data.
      
      
      - **WebSQL access**: This option enables you to [run SQL queries](web-sql-query.md) against cluster databases from the Yandex Cloud management console using Yandex WebSQL.

  1. Under **Modules**, enable the required [Valkey™ modules](../concepts/modules.md).

      For the **Search** module, configure the following settings: **Number of reader threads** and **Number of writer threads**.

      {% note warning %}
      
      You cannot disable modules once enabled.
      
      {% endnote %}

  1. Click **Create cluster**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  To create a Yandex Managed Service for Valkey™ cluster:

  
  1. Check whether the folder has any subnets for cluster hosts:

     ```bash
     yc vpc subnet list
     ```

     If there are no subnets in the folder, [create the right ones](../../vpc/operations/subnet-create.md) in VPC.


  1. View the description of the CLI command for creating a cluster:

      ```bash
      yc managed-redis cluster create --help
      ```

  1. When creating a cluster with the CLI, you cannot explicitly specify the host type and RAM size. Select the appropriate [host class](../concepts/instance-types.md) instead. To view the available host classes, run the following command:

     ```bash
     yc managed-redis resource-preset list
     ```

  1. Run this command, providing the cluster settings (our example lists only some flags):

      
      ```bash
      yc managed-redis cluster create \
        --name <cluster_name> \
        --environment <environment> \
        --redis-version <Valkey™_version> \
        --network-name <network_name> \
        --host zone-id=<availability_zone>,`
              `subnet-id=<subnet_ID>,`
              `assign-public-ip=<public_access>,`
              `replica-priority=<host_priority> \
        --security-group-ids <list_of_security_group_IDs> \
        --enable-tls \
        --persistence-mode <persistence_mode> \
        --resource-preset <host_class> \
        --disk-size <storage_size_in_GB> \
        --disk-size-autoscaling disk-size-limit=<maximum_storage_size_in_GB>,`
                                `planned-usage-threshold=<scheduled_expansion_percentage>,`
                                `emergency-usage-threshold=<immediate_expansion_percentage> \
        --disk-type-id <network-ssd|network-ssd-nonreplicated|local-ssd> \
        --password=<user_password> \
        --backup-window-start <time> \
        --disk-encryption-key-id <KMS_key_ID> \
        --deletion-protection \
        --announce-hostnames <using_FQDNs_instead_of_IP_addresses> \
        --valkey-modules enable-valkey-search=<enable_Valkey-Search_module>,`
                         `valkey-search-reader-threads=<number_of_request_processing_threads>,`
                         `valkey-search-writer-threads=<number_of_indexing_threads>,`
                         `enable-valkey-json=<enable_Valkey-JSON_module>,`
                         `enable-valkey-bloom=<enable_Valkey-Bloom_module>
      ```


      Where:
      * `--environment`: Environment, `prestable` or `production`.
      * `--redis-version`: Valkey™ version, `7.2-valkey`, `8.0-valkey`, `8.1-valkey`, or `9.0-valkey`.
      * `--host`: Host settings:
         * `zone-id`: [Availability zone](../../overview/concepts/geo-scope.md).

         
         * `subnet-id`: [Subnet ID](../../vpc/concepts/network.md#subnet). You must specify this setting if the selected availability zone has more than one subnet.
         * `assign-public-ip`: Host accessibility from the internet via a public IP address, `true` or `false`.


         * `replica-priority`: Host priority for promotion to master if the [primary master fails](../concepts/replication.md#master-failover).
      * `--disk-type-id`: Disk type.

      * `--websql-access`: Enables running [SQL queries](web-sql-query.md) against cluster databases from the Yandex Cloud management console using Yandex WebSQL. The default value is `false`.

      * `--disk-size-autoscaling`: Automatic storage expansion settings:

        * `planned-usage-threshold`: Storage usage percentage to trigger a storage expansion during the next [maintenance window](../concepts/maintenance.md#maintenance-window).
        
          Use a value between `0` and `100`%. The default value is `0`, i.e., automatic expansion is disabled.
        
          If you set this condition, [configure](update.md#change-additional-settings) the maintenance schedule.
        
        * `emergency-usage-threshold`: Storage usage percentage to trigger an immediate storage expansion.
        
          Use a value between `0` and `100`%. The default value is `0`, i.e., automatic expansion is disabled.
        
          {% note warning %}
        
          If you specify both thresholds, `emergency-usage-threshold` must not be less than `planned-usage-threshold`.
        
          {% endnote %}
        
        * `disk-size-limit`: Maximum storage size after expansion, in GB.
        
        
        {% note warning %}
        
        * You cannot decrease the storage size after automatic expansion.
        * During storage resizing, cluster hosts will be stopped and updated one at a time.
        
        {% endnote %}

      * `--persistence-mode`: [Data persistence mode](../concepts/replication.md#persistence).

        The possible values are:
        
        * `ON`: Enable persistence.
        * `OFF`: Disable persistence.
        * `ON_REPLICAS`: Enable persistence on replicas only.

      * `--backup-window-start`: Backup start time in `HH:MM:SS` format.
      * `--deletion-protection`: Cluster protection from accidental deletion, `true` or `false`.

        Even with deletion protection enabled, one can still connect to the cluster manually and delete the data.

      
      * `--disk-encryption-key-id`: Disk encryption using a [custom KMS key](../../kms/concepts/key.md).

        To learn more about disk encryption, see [Storage](../concepts/storage.md#disk-encryption).


      * `--announce-hostnames`: [Use of FQDNs instead of IP addresses](../concepts/network.md#fqdn-ip-setting), `true` or `false`.

        {% note info %}
        
        Some clients do not support this setting and will fail to connect to the cluster hosts. They expect an IP address and will produce errors if you provide an FQDN instead.
        
        {% endnote %}

      * `--valkey-modules`: [Valkey™ module](../concepts/modules.md) parameters:
         * `enable-valkey-search`: Enable the `Valkey-Search` module, `true` or `false`.
         * `valkey-search-reader-threads`: Number of request processing threads in the `Valkey-Search` module.
         * `valkey-search-writer-threads`: Number of indexing threads in the `Valkey-Search` module.
         * `enable-valkey-json`: Enable the `Valkey-JSON` module, `true` or `false`.
         * `enable-valkey-bloom`: Enable the `Valkey-Bloom` module, `true` or `false`.

         {% note warning %}
         
         You cannot disable modules once enabled.
         
         {% endnote %}

      
      You must specify the `subnet-id` if the selected availability zone has more than one subnet.


      The password must be from 8 to 128 characters long and match the `[a-zA-Z0-9@=+?*.,!&#$^<>_-]*` regular expression.

      If you are creating a sharded cluster with the **local-ssd** disk type, specify at least two hosts per shard in the command.

      {% note info %}

      The default [maintenance](../concepts/maintenance.md) mode for new clusters is `anytime`. You can set a specific maintenance period when [updating the cluster settings](update.md#change-additional-settings).

      {% endnote %}


- Terraform {#tf}

  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  To create a Yandex Managed Service for Valkey™ cluster:

    1. In the configuration file, describe the resources you want to create:

       * Database cluster: Description of the cluster and its hosts. You can also configure [DBMS settings](../concepts/settings-list.md) here, if required.
       * Network: Description of the [cloud network](../../vpc/concepts/network.md#network) to host the cluster. If you already have a network in place, you do not need to describe it again.
       * Subnets: Description of the [subnets](../../vpc/concepts/network.md#network) to connect the cluster hosts to. If you already have suitable subnets, you do not need to describe them again.

       Here is an example structure of a configuration file for creating a non-sharded cluster with SSL support:

       ```hcl
       resource "yandex_mdb_redis_cluster_v2" "<cluster_name>" {
         name                = "<cluster_name>"
         environment         = "<environment>"
         network_id          = "<network_ID>"
         security_group_ids  = [ "<list_of_security_group_IDs>" ]
         tls_enabled         = true
         deletion_protection = <cluster_deletion_protection>
         announce_hostnames  = <using_FQDNs_instead_of_IP_addresses>
         persistence_mode    = "<persistence_mode>"

         disk_size_autoscaling = {
           planned_usage_threshold   = "<scheduled_expansion_percentage>"
           emergency_usage_threshold = "<immediate_expansion_percentage>"
           disk_size_limit           = "<maximum_storage_size_in_GiB>"
         }

         config = {
           password = "<password>"
           version  = "<Valkey™_version>"
         }

         resources = {
           resource_preset_id = "<host_class>"
           disk_type_id       = "<disk_type>"
           disk_size          = <storage_size_in_GB>
         }

         hosts = {
           "host1" = {
             zone             = "<availability_zone>"
             subnet_id        = "<subnet_ID>"
             assign_public_ip = <public_access>
             replica_priority = <host_priority>
           }
         }
       }

       resource "yandex_vpc_network" "<network_name>" { name = "<network_name>" }

       resource "yandex_vpc_subnet" "<subnet_name>" {
         name           = "<subnet_name>"
         zone           = "<availability_zone>"
         network_id     = "<network_ID>"
         v4_cidr_blocks = ["<range>"]
       }
       ```

       Where:
       * `environment`: Environment, `PRESTABLE` or `PRODUCTION`.
       * `deletion_protection`: Cluster deletion protection, `true` or `false`.

           Even with deletion protection enabled, one can still connect to the cluster manually and delete the data.

       * `disk_size_autoscaling`: Automatic storage expansion settings:

           * `planned_usage_threshold`: Storage usage percentage to trigger a storage expansion during the next [maintenance window](../concepts/maintenance.md#maintenance-window).
           
               Use a value between `0` and `100`%. The default value is `0`, i.e., automatic expansion is disabled.
           
               If you set this condition, configure the maintenance schedule in the `maintenance_window` section.
           
           * `emergency_usage_threshold`: Storage usage percentage to trigger an immediate storage expansion.
           
               Use a value between `0` and `100`%. The default value is `0`, i.e., automatic expansion is disabled.
           
               {% note warning %}
           
               If you specify both thresholds, `emergency_usage_threshold` must not be less than `planned_usage_threshold`.
           
               {% endnote %}
           
           * `disk_size_limit`: Maximum storage size after the increase, in gibibytes.
           
           
           {% note warning %}
           
           * You cannot decrease the storage size after automatic expansion.
           * During storage resizing, cluster hosts will be stopped and updated one at a time.
           
           {% endnote %}

       * `announce_hostnames`: [Use of FQDNs instead of IP addresses](../concepts/network.md#fqdn-ip-setting), `true` or `false`.

           {% note info %}
           
           Some clients do not support this setting and will fail to connect to the cluster hosts. They expect an IP address and will produce errors if you provide an FQDN instead.
           
           {% endnote %}

       * `persistence_mode`: [Data persistence mode](../concepts/replication.md#persistence).

           The possible values are:
           
           * `ON`: Enable persistence.
           * `OFF`: Disable persistence.
           * `ON_REPLICAS`: Enable persistence on replicas only.

       * `version`: Valkey™ version, `7.2-valkey`, `8.0-valkey`, `8.1-valkey`, or `9.0-valkey`.
       * `hosts`: List of hosts and their settings in `"<host_name>" = { <host_settings> }` format. The host name must be unique within the cluster.

           For each host, the following parameters are available:

           * `zone_id`: [Availability zone](../../overview/concepts/geo-scope.md).
           * `subnet_id`: [ID of the subnet](../../vpc/concepts/network.md#subnet) in the selected availability zone.
           * `assign_public_ip`: Public access to the host, `true` or `false`.
           * `replica_priority`: Host priority for master promotion during [failover](../concepts/replication.md#master-failover).

       The password must be from 8 to 128 characters long and match the `[a-zA-Z0-9@=+?*.,!&#$^<>_-]*` regular expression.

       If you are creating a sharded cluster with the **local-ssd** disk type, specify at least two hosts per shard in the configuration file.

    1. To set up the [maintenance window](../concepts/maintenance.md) that will also apply to stopped clusters, add the `maintenance_window` section to the cluster description:
       
       ```hcl
       resource "yandex_mdb_redis_cluster_v2" "<cluster_name>" {
         ...
         maintenance_window = {
           type = <maintenance_type>
           day  = "<day_of_week>"
           hour = <hour>
         }
         ...
       }
       ```
       
       Where:
       
       * `type`: Maintenance type. The possible values include:
           * `ANYTIME`: Any time.
           * `WEEKLY`: On a schedule.
       * `day`: Day of week for the `WEEKLY` type, i.e., `MON`, `TUE`, `WED`, `THU`, `FRI`, `SAT`, or `SUN`.
       * `hour`: Sequence number of UTC hour interval for the `WEEKLY` type, from `1` to `24`.
       
         > For example, `1` stands for the interval from `00:00` to `01:00`, and `5`, from `04:00` to `05:00`.

    1. To encrypt the disk with a [custom KMS key](../../kms/concepts/key.md), add the `disk_encryption_key_id` argument to the cluster description:

        ```hcl
        resource "yandex_mdb_redis_cluster_v2" "<cluster_name>" {
          ...
          disk_encryption_key_id = "<KMS_key_ID>"
        }
        ```

        To learn more about disk encryption, see [Storage](../concepts/storage.md#disk-encryption).

    1. To enable [Valkey™ modules](../concepts/modules.md), add the `modules` section to the cluster description:

        ```hcl
        resource "yandex_mdb_redis_cluster_v2" "<cluster_name>" {
          ...
          modules = {
            valkey_bloom = {
              enabled = <enable_Valkey-Bloom_module>
            }
            valkey_json = {
              enabled = <enable_Valkey-JSON_module>
            }
            valkey_search = {
              enabled        = <enable_Valkey-Search_module>
              reader_threads = <number_of_request_processing_threads>
              writer_threads = <number_of_indexing_threads>
            }
          }
        }
        ```

       Where:

        * `valkey_bloom.enabled`: Enable the `Valkey-Bloom` module, `true` or `false`.
        * `valkey_json.enabled`: Enable the `Valkey-JSON` module, `true` or `false`.
        * `valkey_search.enabled`: Enable the `Valkey-Search` module, `true` or `false`.
        * `valkey_search.reader_threads`: Number of request processing threads in the `Valkey-Search` module.
        * `valkey_search.writer_threads`: Number of indexing threads in the `Valkey-Search` module.

    1. Make sure the settings are correct.

        1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
        1. Run this command:
        
           ```bash
           terraform validate
           ```
        
           Terraform will show any errors found in your configuration files.

    1. Create the cluster.

        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.

    This will create all the resources you need in the specified folder, and the terminal will display the [FQDNs of the cluster hosts](../concepts/network.md#hostname). You can check the new resources and their settings using the [management console](https://console.yandex.cloud).

    For more information about the resources you can create with Terraform, see [this provider guide](../../terraform/resources/mdb_redis_cluster_v2.md).

    {% note warning "Timeouts" %}
    
    The Terraform provider sets the following timeouts for Yandex Managed Service for Valkey™ cluster operations:
    
    * Creating a cluster, including by restoring it from a backup: 15 minutes.
    * Editing a cluster: 60 minutes.
    * Deleting a cluster: 15 minutes.
    
    Operations exceeding the timeout are aborted.
    
    {% cut "How do I change these limits?" %}
    
    Add the `timeouts` section to your cluster description, such as the following:
    
    ```hcl
    resource "yandex_mdb_redis_cluster_v2" "<cluster_name>" {
      ...
      timeouts = {
        create = "1h30m" # 1 hour 30 minutes
        update = "2h"    # 2 hours
        delete = "30m"   # 30 minutes
      }
    }
    ```
    
    {% endcut %}
    
    {% endnote %}


- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Create a file named `body.json` and paste the following code into it:

        
        ```json
        {
          "folderId": "<folder_ID>",
          "name": "<cluster_name>",
          "environment": "<environment>",
          "configSpec": {
            "version": "<Valkey™_version>",
            "resources": {
              "resourcePresetId": "<host_class>",
              "diskSize": "<storage_size_in_bytes>",
              "diskTypeId": "<disk_type>"
            },
            "diskSizeAutoscaling": {
              "plannedUsageThreshold": "<scheduled_expansion_percentage>",
              "emergencyUsageThreshold": "<immediate_expansion_percentage>",
              "diskSizeLimit": "<maximum_storage_size_in_bytes>"
            },
            "access": {
              "webSql": <access_from_WebSQL>
            },
            "redis": {
              "password": "<user_password>"
            },
            "modules": {
              "valkeySearch": {
                "enabled": "<enable_Valkey-Search_module>",
                "readerThreads": "<number_of_request_processing_threads>",
                "writerThreads": "<number_of_indexing_threads>"
              },
              "valkeyJson": {
                "enabled": "<enable_Valkey-JSON_module>"
              },
              "valkeyBloom": {
                "enabled": "<enable_Valkey-Bloom_module>"
              }
            }
          },
          "hostSpecs": [
            {
              "zoneId": "<availability_zone>",
              "subnetId": "<subnet_ID>",
              "shardName": "<shard_name>",
              "replicaPriority": "<host_priority>",
              "assignPublicIp": <public_access_to_cluster_host>
            },
            { <similar_settings_for_host_2> },
            { ... },
            { <similar_settings_for_host_N> }
          ],
          "networkId": "<network_ID>",
          "sharded": <cluster_sharding>,
          "securityGroupIds": [
            "<security_group_1_ID>",
            "<security_group_2_ID>",
            ...
            "<security_group_N_ID>"
          ],
          "tlsEnabled": <encrypted_TLS_connection_support>,
          "deletionProtection": <cluster_deletion_protection>,
          "announceHostnames": <using_FQDNs_instead_of_IP_addresses>,
          "persistenceMode": "<persistence_mode>"
        }
        ```




        Where:

        * `folderId`: Folder ID. You can get it from the [list of your cloud folders](../../resource-manager/operations/folder/get-id.md).
        * `name`: Cluster name.
        * `environment`: Environment, `PRESTABLE` or `PRODUCTION`.
        * `configSpec`: Cluster settings:

            * `version`: Valkey™ version, `7.2-valkey`, `8.0-valkey`, `8.1-valkey`, or `9.0-valkey`.
            * `resources`: Cluster resources:

                * `resourcePresetId`: [Host class](../concepts/instance-types.md).
                * `diskSize`: Disk size, in bytes.
                * `diskTypeId`: [Disk type](../concepts/storage.md).

            * `diskSizeAutoscaling`: Automatic storage expansion settings:
            
              * `plannedUsageThreshold`: Storage usage percentage to trigger a storage expansion during the next [maintenance window](../concepts/maintenance.md#maintenance-window).
            
                Use a value between `0` and `100`%. The default value is `0`, i.e., automatic expansion is disabled.
            
                If you set this condition, configure the `maintenanceWindow`.
            
              * `emergencyUsageThreshold`: Storage usage percentage to trigger an immediate storage expansion.
            
                Use a value between `0` and `100`%. The default value is `0`, i.e., automatic expansion is disabled.
            
                {% note warning %}
            
                If you specify both thresholds, `emergencyUsageThreshold` must not be less than `plannedUsageThreshold`.
            
                {% endnote %}
            
              * `diskSizeLimit`: Maximum storage size after expansion, in bytes.
            
              
              {% note warning %}
              
              * You cannot decrease the storage size after automatic expansion.
              * During storage resizing, cluster hosts will be stopped and updated one at a time.
              
              {% endnote %}

            
            * `access.webSql`: Access to cluster databases from the Yandex Cloud management console using [Yandex WebSQL](../../websql/index.md), `true` or `false`.


            * `redis.password`: Password.

            * `modules`: [Valkey™ module](../concepts/modules.md) parameters:

               * `valkeySearch.enabled`: Enable the `Valkey-Search` module, `true` or `false`. What you can set up for the module:
                   * `valkeySearch.readerThreads`: Number of request processing threads.
                   * `valkeySearch.writerThreads`: Number of indexing threads.
               * `valkeyJson.enabled`: Enable the `Valkey-JSON` module, `true` or `false`.
               * `valkeyBloom.enabled`: Enable the `Valkey-Bloom` module, `true` or `false`.

               {% note warning %}
               
               You cannot disable modules once enabled.
               
               {% endnote %}

        * `hostSpecs`: Host settings:

            * `zoneId`: [Availability zone](../../overview/concepts/geo-scope.md).
            * `subnetId`: [Subnet ID](../../vpc/concepts/network.md#subnet). Specify it if the selected availability zone has two or more subnets.
            * `shardName`: Shard name for the host. This setting only applies when `sharded` is set to `true`.
            * `replicaPriority`: Host priority for master promotion during [failover](../concepts/replication.md#master-failover).
            * `assignPublicIp`: Host accessibility from the internet via a public IP address, `true` or `false`. You can enable public access only if `tlsEnabled` is set to `true`.

        * `networkId`: ID of the [network](../../vpc/concepts/network.md#network) the cluster will be deployed in.

        * `sharded`: [Cluster sharding](../concepts/sharding.md), `true` or `false`.

            {% note warning %}

            You cannot disable sharding in a cluster where it is already enabled. You can create a non-sharded cluster and [enable sharding](update.md#enable-sharding) later, if required.

            {% endnote %}

            If you are creating a sharded cluster with the `local-ssd` disk type, specify at least two hosts per shard, adding the appropriate number of `hostSpecs` sections.

        
        * `securityGroupIds`: [Security group](../concepts/network.md#security-groups) IDs.


        * `tlsEnabled`: Support for encrypted TLS connections to the cluster, `true` or `false`.

            {% note warning %}

            You can enable encrypted connections only when creating a new cluster. You cannot disable encryption for an existing cluster.

            {% endnote %}

        * `deletionProtection`: Cluster deletion protection, `true` or `false`.

            Even with deletion protection enabled, one can still connect to the cluster manually and delete the data.

        * `announceHostnames`: [Using FQDNs instead of IP addresses](../concepts/network.md#fqdn-ip-setting), `true` or `false`.

            {% note info %}
            
            Some clients do not support this setting and will fail to connect to the cluster hosts. They expect an IP address and will produce errors if you provide an FQDN instead.
            
            {% endnote %}

        * `persistenceMode`: [Data persistence mode](../concepts/replication.md#persistence).

            The possible values are:
            
            * `ON`: Enable persistence.
            * `OFF`: Disable persistence.
            * `ON_REPLICAS`: Enable persistence on replicas only.

    1. Call the [Cluster.Create](../api-ref/Cluster/create.md) method, e.g., via the following [cURL](https://curl.se/) request:

        ```bash
        curl \
            --request POST \
            --header "Authorization: Bearer $IAM_TOKEN" \
            --header "Content-Type: application/json" \
            --url 'https://mdb.api.cloud.yandex.net/managed-redis/v1/clusters' \
            --data "@body.json"
        ```

    1. Check the [server response](../api-ref/Cluster/create.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.

    1. Create a file named `body.json` and paste the following code into it:

        
        ```json
        {
          "folder_id": "<folder_ID>",
          "name": "<cluster_name>",
          "environment": "<environment>",
          "config_spec": {
            "version": "<Valkey™_version>",
            "resources": {
              "resource_preset_id": "<host_class>",
              "disk_size": "<storage_size_in_bytes>",
              "disk_type_id": "<disk_type>"
            },
            "disk_size_autoscaling": {
              "planned_usage_threshold": "<scheduled_expansion_percentage>",
              "emergency_usage_threshold": "<immediate_expansion_percentage>",
              "disk_size_limit": "<maximum_storage_size_in_bytes>"
            },
            "access": {
              "web_sql": <access_from_WebSQL>
            },
            "redis": {
              "password": "<user_password>"
            },
            "modules": {
              "valkey_search": {
                "enabled": "<enable_Valkey-Search_module>",
                "reader_threads": "<number_of_request_processing_threads>",
                "writer_threads": "<number_of_indexing_threads>"
              },
              "valkey_json": {
                "enabled": "<enable_Valkey-JSON_module>"
              },
              "valkey_bloom": {
                "enabled": "<enable_Valkey-Bloom_module>"
              }
            }
          },
          "host_specs": [
            {
              "zone_id": "<availability_zone>",
              "subnet_id": "<subnet_ID>",
              "shard_name": "<shard_name>",
              "replica_priority": "<host_priority>",
              "assign_public_ip": <public_access_to_cluster_host>
            },
            { <similar_settings_for_host_2> },
            { ... },
            { <similar_settings_for_host_N> }
          ],
          "network_id": "<network_ID>",
          "sharded": <cluster_sharding>,
          "security_group_ids": [
            "<security_group_1_ID>",
            "<security_group_2_ID>",
            ...
            "<security_group_N_ID>"
          ],
          "tls_enabled": <encrypted_TLS_connection_support>,
          "deletion_protection": <cluster_deletion_protection>,
          "announce_hostnames": <using_FQDNs_instead_of_IP_addresses>,
          "persistence_mode": "<persistence_mode>"
        }
        ```




        Where:

        * `folder_id`: Folder ID. You can get it with the [list of folders in the cloud](../../resource-manager/operations/folder/get-id.md).
        * `name`: Cluster name.
        * `environment`: Environment, `PRESTABLE` or `PRODUCTION`.
        * `config_spec`: Cluster settings:

            * `version`: Valkey™ version, `7.2-valkey`, `8.0-valkey`, `8.1-valkey`, or `9.0-valkey`.
            * `resources`: Cluster resources:

                * `resource_preset_id`: [Host class](../concepts/instance-types.md).
                * `disk_size`: Disk size, in bytes.
                * `disk_type_id`: [Disk type](../concepts/storage.md).

            * `disk_size_autoscaling`: Automatic storage expansion settings:
            
              * `planned_usage_threshold`: Storage usage percentage to trigger a storage expansion during the next [maintenance window](../concepts/maintenance.md#maintenance-window).
            
                Use a value between `0` and `100`%. The default value is `0`, i.e., automatic expansion is disabled.
            
                If you set this condition, configure the `maintenance_window`.
            
              * `emergency_usage_threshold`: Storage usage percentage to trigger an immediate storage expansion.
            
                Use a value between `0` and `100`%. The default value is `0`, i.e., automatic expansion is disabled.
            
                {% note warning %}
            
                If you specify both thresholds, `emergency_usage_threshold` must not be less than `planned_usage_threshold`.
            
                {% endnote %}
            
              * `disk_size_limit`: Maximum storage size after expansion, in bytes.
              
              
              {% note warning %}
              
              * You cannot decrease the storage size after automatic expansion.
              * During storage resizing, cluster hosts will be stopped and updated one at a time.
              
              {% endnote %}

            
            * `access.web_sql`: Access to cluster databases from the Yandex Cloud management console using [Yandex WebSQL](../../websql/index.md), `true` or `false`.


            * `redis.password`: Password.

            * `modules`: [Valkey™ module](../concepts/modules.md) parameters:

               * `valkey_search.enabled`: Enable the `Valkey-Search` module, `true` or `false`. What you can set up for the module:
                   * `valkey_search.reader_threads`: Number of request processing threads.
                   * `valkey_search.writer_threads`: Number of indexing threads.
               * `valkey_json.enabled`: Enable the `Valkey-JSON` module, `true` or `false`.
               * `valkey_bloom.enabled`: Enable the `Valkey-Bloom` module, `true` or `false`.

               {% note warning %}
               
               You cannot disable modules once enabled.
               
               {% endnote %}

        * `host_specs`: Host settings:

            * `zone_id`: [Availability zone](../../overview/concepts/geo-scope.md).
            * `subnet_id`: [Subnet ID](../../vpc/concepts/network.md#subnet). Specify it if the selected availability zone has two or more subnets.
            * `shard_name`: Shard name for the host. This setting only applies when `sharded` is set to `true`.
            * `replica_priority`: Host priority for master promotion during [failover](../concepts/replication.md#master-failover).
            * `assign_public_ip`: Host accessibility from the internet via a public IP address, `true` or `false`. You can enable public access only if `tls_enabled` is set to `true`.

        * `network_id`: ID of the [network](../../vpc/concepts/network.md#network) the cluster will be deployed in.

        * `sharded`: [Cluster sharding](../concepts/sharding.md), `true` or `false`.

            {% note warning %}

            You cannot disable sharding in a cluster where it is already enabled. You can create a non-sharded cluster and [enable sharding](update.md#enable-sharding) later, if required.

            {% endnote %}

            If you are creating a sharded cluster with the `local-ssd` disk type, specify at least two hosts per shard, adding the appropriate number of `host_specs` sections.

        
        * `security_group_ids`: [Security group](../concepts/network.md#security-groups) IDs.


        * `tls_enabled`: Support for encrypted TLS connections to the cluster, `true` or `false`.

            {% note warning %}

            You can enable encrypted connections only when creating a new cluster. You cannot disable encryption for an existing cluster.

            {% endnote %}

        * `deletion_protection`: Cluster deletion protection, `true` or `false`.

            Even with deletion protection enabled, one can still connect to the cluster manually and delete the data.

        * `announce_hostnames`: [Using FQDNs instead of IP addresses](../concepts/network.md#fqdn-ip-setting), `true` or `false`.

            {% note info %}
            
            Some clients do not support this setting and will fail to connect to the cluster hosts. They expect an IP address and will produce errors if you provide an FQDN instead.
            
            {% endnote %}

        * `persistence_mode`: [Data persistence mode](../concepts/replication.md#persistence).

            The possible values are:
            
            * `ON`: Enable persistence.
            * `OFF`: Disable persistence.
            * `ON_REPLICAS`: Enable persistence on replicas only.

    1. Call the [ClusterService.Create](../api-ref/grpc/Cluster/create.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        ```bash
        grpcurl \
            -format json \
            -import-path ~/cloudapi/ \
            -import-path ~/cloudapi/third_party/googleapis/ \
            -proto ~/cloudapi/yandex/cloud/mdb/redis/v1/cluster_service.proto \
            -rpc-header "Authorization: Bearer $IAM_TOKEN" \
            -d @ \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.redis.v1.ClusterService.Create \
            < body.json
        ```

    1. Check the [server response](../api-ref/grpc/Cluster/create.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}


{% note warning %}

If you specified security group IDs when creating a cluster, you may need to [configure these security groups](connect/index.md#configuring-security-groups) to enable cluster access.

{% endnote %}


## Creating a cluster copy {#duplicate}

You can create a Valkey™ cluster with the settings of another one created earlier. Do this by importing the original Valkey™ cluster configuration into Terraform. This way, you can either create an identical copy or use the imported configuration as the baseline and modify it as needed. The import feature is handy when the original Valkey™ cluster has a lot of settings and you need to create a similar one.

To create a Valkey™ cluster copy:

{% list tabs group=instructions %}

- 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. In your current working directory, create a `.tf` file with the following contents:

        ```hcl
        resource "yandex_mdb_redis_cluster_v2" "old" { }
        ```

    1. Save the ID of the original Valkey™ cluster to an environment variable:

        ```bash
        export REDIS_CLUSTER_ID=<cluster_ID>
        ```

        You can get the ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. Import the original Valkey™ cluster settings to the Terraform configuration:

        ```bash
        terraform import yandex_mdb_redis_cluster_v2.old ${REDIS_CLUSTER_ID}
        ```

    1. Get the imported configuration:

        ```bash
        terraform show
        ```

    1. Copy it from your terminal and paste it into the `.tf` file.
    1. Create a new directory `imported-cluster` and move your configuration file there.
    1. Modify the configuration so that you can use it to create a new cluster:

        * Specify the new cluster name in the `resource` string and the `name` parameter.
        * Delete `created_at`, `health`, `id`, and `status`.
        * Add the `password` parameter to the `config` section.
        * If you have `notify_keyspace_events = "\"\""` in the `config` section, delete this parameter.
        * If `sharded = false`, delete the `shard_name` parameters from the `hosts` section.
        * If the `maintenance_window` section contains `type = "ANYTIME"`, delete the `hour` argument.
        * Optionally, make further changes if you need a customized configuration.

    1. [Get the authentication credentials](../../tutorials/infrastructure-management/terraform-quickstart.md#get-credentials) in the `imported-cluster` directory.

    1. In the same directory, [configure and initialize the provider](../../tutorials/infrastructure-management/terraform-quickstart.md#configure-provider). Instead of manually creating the provider configuration file, you can [download it](https://github.com/yandex-cloud-examples/yc-terraform-provider-settings/blob/main/provider.tf).

    1. Move the configuration file to the `imported-cluster` directory and [specify the arguments](../../tutorials/infrastructure-management/terraform-quickstart.md#configure-provider). If you have not set the authentication credentials as environment variables, specify them in the configuration file.

    1. Validate your Terraform configuration:

        ```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).

    {% note warning "Timeouts" %}
    
    The Terraform provider sets the following timeouts for Yandex Managed Service for Valkey™ cluster operations:
    
    * Creating a cluster, including by restoring it from a backup: 15 minutes.
    * Editing a cluster: 60 minutes.
    * Deleting a cluster: 15 minutes.
    
    Operations exceeding the timeout are aborted.
    
    {% cut "How do I change these limits?" %}
    
    Add the `timeouts` section to your cluster description, such as the following:
    
    ```hcl
    resource "yandex_mdb_redis_cluster_v2" "<cluster_name>" {
      ...
      timeouts = {
        create = "1h30m" # 1 hour 30 minutes
        update = "2h"    # 2 hours
        delete = "30m"   # 30 minutes
      }
    }
    ```
    
    {% endcut %}
    
    {% endnote %}

{% endlist %}

## Examples {#examples}

### Creating a single-host cluster {#creating-a-single-host-cluster}

{% list tabs group=instructions %}

- CLI {#cli}

  To create a single-host cluster, provide one `--host` parameter.

  Create a Yandex Managed Service for Valkey™ cluster with the following test specifications:

  
  * Name: `myredis`.
  * Version: `9.0-valkey``.
  * Environment: `production`.
  * Network: `default`.
  * A single `hm2.nano` host in the `b0rcctk2rvtr********` subnet, `ru-central1-a` availability zone and security group with the `enp6saqnq4ie244g67sb` ID, with public access and a [host priority](../concepts/replication.md#master-failover) of `50`.
  * SSL support: Enabled.
  * Network SSD storage (`network-ssd`): 16 GB.
  * Password: `user1user1`.
  * Deletion protection: Enabled.


  Run this command:

  
  ```bash
  yc managed-redis cluster create \
    --name myredis \
    --redis-version 9.0-valkey` \
    --environment production \
    --network-name default \
    --resource-preset hm2.nano \
    --host zone-id=ru-central1-a,subnet-id=b0rcctk2rvtr********,assign-public-ip=true,replica-priority=50 \
    --security-group-ids enp6saqnq4ie244g67sb \
    --enable-tls \
    --disk-type-id network-ssd \
    --disk-size 16 \
    --password=user1user1 \
    --deletion-protection
  ```



- Terraform {#tf}

  Create a Yandex Managed Service for Valkey™ cluster and its network with the following test specifications:

    * Name: `myredis`.
    * Version: `9.0-valkey``.
    * Environment: `PRODUCTION`.
    * Cloud ID: `b1gq90dgh25bebiu75o`.
    * Folder ID: `b1gia87mbaomkfvsleds`.
    * Network: `mynet` (new).
    * A single `hm2.nano` class host in the new subnet called `mysubnet`, `ru-central1-a` availability zone, with public access and a [host priority](../concepts/replication.md#master-failover) of `50`. `mysubnet` CIDR range: `10.5.0.0/24`.
    * New security group `redis-sg` allowing connections via port `6380` from any addresses in `mysubnet`.
    * SSL support: Enabled.
    * Network SSD storage (`network-ssd`): 16 GB.
    * Password: `user1user1`.
    * Deletion protection: Enabled.

  The configuration file for this cluster is as follows:

  ```hcl
  resource "yandex_mdb_redis_cluster_v2" "myredis" {
    name                = "myredis"
    environment         = "PRODUCTION"
    network_id          = yandex_vpc_network.mynet.id
    security_group_ids  = [ yandex_vpc_security_group.redis-sg.id ]
    tls_enabled         = true
    deletion_protection = true

    config = {
      password = "user1user1"
      version  = "9.0-valkey`"
    }

    resources = {
      resource_preset_id = "hm2.nano"
      disk_type_id       = "network-ssd"
      disk_size          = 16
    }

    hosts = {
      "host1" = {
        zone             = "ru-central1-a"
        subnet_id        = yandex_vpc_subnet.mysubnet.id
        assign_public_ip = true
        replica_priority = 50
      }
    }
  }

  resource "yandex_vpc_network" "mynet" { name = "mynet" }

  resource "yandex_vpc_security_group" "redis-sg" {
    name       = "redis-sg"
    network_id = yandex_vpc_network.mynet.id

    ingress {
      description    = "Valkey™"
      port           = 6380
      protocol       = "TCP"
      v4_cidr_blocks = ["10.5.0.0/24"]
    }
  }

  resource "yandex_vpc_subnet" "mysubnet" {
    name           = "mysubnet"
    zone           = "ru-central1-a"
    network_id     = yandex_vpc_network.mynet.id
    v4_cidr_blocks = ["10.5.0.0/24"]
  }
  ```


{% endlist %}

### Creating a sharded cluster with a single shard {#creating-a-single-shard-sharded-cluster}

{% list tabs group=instructions %}

- CLI {#cli}

  Create a [sharded](../concepts/sharding.md) Yandex Managed Service for Valkey™ cluster with the following test specifications:

  
  * Name: `myredis`.
  * Version: `9.0-valkey``.
  * Environment: `production`.
  * Sharding: Enabled.
  * SSL support: Enabled.
  * Deletion protection: Enabled.
  * Network: `default`.
  * Security group ID: `enp6saqnq4ie244g67sb`.
  * Host class: `hm2.nano`.
  * A single host in the shard called `shard1`, in the `b0rcctk2rvtr********` subnet, `ru-central1-a` availability zone, with public access and a [host priority](../concepts/replication.md#master-failover) of `50`.
  * Network SSD storage (`network-ssd`): 16 GB.
  * Password: `user1user1`.


  Run this command:

  
  ```bash
  yc managed-redis cluster create \
    --name myredis \
    --redis-version 9.0-valkey` \
    --environment production \
    --sharded \
    --enable-tls \
    --deletion-protection \
    --network-name default \
    --security-group-ids enp6saqnq4ie244g67sb \
    --resource-preset hm2.nano \
    --host shard-name=shard1,subnet-id=b0rcctk2rvtr********,zone-id=ru-central1-a,assign-public-ip=true,replica-priority=50 \
    --disk-type-id network-ssd \
    --disk-size 16 \
    --password user1user1
  ```



- Terraform {#tf}

  Create a [sharded](../concepts/sharding.md) Yandex Managed Service for Valkey™ cluster and a network for it with the following test specifications:

  * Name: `myredis`.
  * Version: `9.0-valkey``.
  * Environment: `PRODUCTION`.
  * Sharding: Enabled.
  * SSL support: Enabled.
  * Deletion protection: Enabled.
  * Network: `mynet` (new) with a single subnet: `mysubnet`. CIDR range for `mysubnet`: `10.5.0.0/24`.
  * New security group `redis-sg` allowing connections via port `6380` from any addresses in `mysubnet`.
  * Host class: `hm2.nano`.
  * A single host in the shard called `shard1`, in the `mysubnet` subnet, `ru-central1-a` availability zone, with public access and a [host priority](../concepts/replication.md#master-failover) of `50`.
  * Network SSD storage (`network-ssd`): 16 GB.
  * Password: `user1user1`.

  The configuration file for this cluster is as follows:

  ```hcl
  resource "yandex_mdb_redis_cluster_v2" "myredis" {
    name                = "myredis"
    environment         = "PRODUCTION"
    sharded             = true
    tls_enabled         = true
    deletion_protection = true
    network_id          = yandex_vpc_network.mynet.id
    security_group_ids  = [yandex_vpc_security_group.redis-sg.id]

    config = {
      version  = "9.0-valkey`"
      password = "user1user1"
    }

    resources = {
      resource_preset_id = "hm2.nano"
      disk_type_id       = "network-ssd"
      disk_size          = 16
    }

    hosts = {
      "host1" = {
        shard_name       = "shard1"
        subnet_id        = yandex_vpc_subnet.mysubnet.id
        zone             = "ru-central1-a"
        assign_public_ip = true
        replica_priority = 50
      }
    }
  }
  
  resource "yandex_vpc_network" "mynet" { name = "mynet" }
  
  resource "yandex_vpc_subnet" "mysubnet" {
    name           = "mysubnet"
    zone           = "ru-central1-a"
    network_id     = yandex_vpc_network.mynet.id
    v4_cidr_blocks = ["10.5.0.0/24"]
  }
  
  resource "yandex_vpc_security_group" "redis-sg" {
    name       = "redis-sg"
    network_id = yandex_vpc_network.mynet.id
  
    ingress {
      description    = "Valkey™"
      port           = 6380
      protocol       = "TCP"
      v4_cidr_blocks = ["10.5.0.0/24"]
    }
  }
  ```


{% endlist %}


### Creating a sharded cluster with three shards {#creating-a-sharded-cluster}


{% list tabs group=instructions %}

- Terraform {#tf}

    Create a [sharded](../concepts/sharding.md) Yandex Managed Service for Valkey™ cluster with the following test specifications:

    * Name: `myredis`.
    * Version: `9.0-valkey``.
    * Environment: `PRODUCTION`.
    * Cloud ID: `b1gq90dgh25bebiu75o`.
    * Folder ID: `b1gia87mbaomkfvsleds`.
    * Network: `mynet` (new).
    * Three subnets in the `mynet` network, one in each availability zone:
      * `subnet-a` with the `10.1.0.0/24` range
      * `subnet-b` with the `10.2.0.0/24` range
      * `subnet-d` with the `10.3.0.0/24` range
    * Three `hm2.nano` class hosts, one in each subnet.
    * New security group `redis-sg` allowing connections via ports `6379` and `26379` ([Valkey™ Sentinel](connect/index.md)) from any subnet addresses.
    * Network SSD storage (`network-ssd`): 16 GB.
    * Password: `user1user1`.
    * Deletion protection: Enabled.

    The configuration file for this cluster is as follows:

    ```hcl
    resource "yandex_mdb_redis_cluster_v2" "myredis" {
      name                = "myredis"
      environment         = "PRODUCTION"
      network_id          = yandex_vpc_network.mynet.id
      security_group_ids  = [yandex_vpc_security_group.redis-sg.id]
      sharded             = true
      deletion_protection = true

      config = {
        password = "user1user1"
        version  = "9.0-valkey`"
      }

      resources = {
        resource_preset_id = "hm2.nano"
        disk_type_id       = "network-ssd"
        disk_size          = 16
      }

      hosts = {
        "host1" = {
          zone       = "ru-central1-a"
          subnet_id  = yandex_vpc_subnet.subnet-a.id
          shard_name = "shard1"
        }

        "host2" = {
          zone       = "ru-central1-b"
          subnet_id  = yandex_vpc_subnet.subnet-b.id
          shard_name = "shard2"
        }

        "host3" = {
          zone       = "ru-central1-d"
          subnet_id  = yandex_vpc_subnet.subnet-d.id
          shard_name = "shard3"
        }
      }
    }

    resource "yandex_vpc_network" "mynet" { name = "mynet" }

    resource "yandex_vpc_subnet" "subnet-a" {
      name           = "subnet-a"
      zone           = "ru-central1-a"
      network_id     = yandex_vpc_network.mynet.id
      v4_cidr_blocks = ["10.1.0.0/24"]
    }

    resource "yandex_vpc_subnet" "subnet-b" {
      name           = "subnet-b"
      zone           = "ru-central1-b"
      network_id     = yandex_vpc_network.mynet.id
      v4_cidr_blocks = ["10.2.0.0/24"]
    }

    resource "yandex_vpc_subnet" "subnet-d" {
      name           = "subnet-d"
      zone           = "ru-central1-d"
      network_id     = yandex_vpc_network.mynet.id
      v4_cidr_blocks = ["10.3.0.0/24"]
    }

    resource "yandex_vpc_security_group" "redis-sg" {
      name       = "redis-sg"
      network_id = yandex_vpc_network.mynet.id

      ingress {
        description    = "Valkey™"
        port           = 6379
        protocol       = "TCP"
        v4_cidr_blocks = [
          "10.1.0.0/24",
          "10.2.0.0/24",
          "10.3.0.0/24"
        ]
      }

      ingress {
        description    = "Valkey™ Sentinel"
        port           = 26379
        protocol       = "TCP"
        v4_cidr_blocks = [
          "10.1.0.0/24",
          "10.2.0.0/24",
          "10.3.0.0/24"
        ]
      }
    }
    ```

{% endlist %}