Creating a Redis cluster
A Redis cluster is one or more database hosts between which you can configure replication. Replication is enabled by default in any cluster consisting of more than one host: the master host accepts write requests and asynchronously duplicates changes on replicas.
For more about Managed Service for Redis cluster structure, see Resource relationships in Managed Service for Redis.
Note
- The number of hosts you can create together with a Redis cluster depends on the selected disk type and host class as well as on whether sharding is enabled.
- Available disk types depend on the selected host class.
How to create a Redis cluster
-
In the management console
, go to the folder to create a DB cluster in. -
Select Managed Service for Redis.
-
Click Create cluster.
-
Under Basic parameters:
-
Enter a name for the cluster in the Cluster name field. It must be unique within the folder.
-
(Optional) Add a cluster description.
-
Select the environment where you want to create the cluster (you cannot change the environment once the cluster is created):
PRODUCTION
: For stable versions of your apps.PRESTABLE
: For testing purposes. The prestable environment is similar to the production environment and likewise covered by the SLA, but it is the first to get new functionalities, improvements, and bug fixes. In the prestable environment, you can test compatibility of new versions with your application.
-
Select the DBMS version.
-
If necessary, enable cluster sharding.
Warning
You can only enable sharding when you create a new cluster. You cannot shard an existing non-sharded cluster or disable sharding for a cluster that it is enabled for.
-
If required, enable support for encrypted SSL connections to the cluster.
Warning
You can only enable connection encryption when creating a new cluster. You cannot disable encryption for a cluster that it is enabled for.
-
-
Under Host class:
- Select a platform in the Platform field.
- Specify the Type of the VM to deploy hosts on.
- Select a host configuration that defines the technical specifications of the VMs where the DB hosts will be deployed. Changing the configuration changes the properties of all the previously created hosts.
-
Under Size of storage:
-
Select the disk type:
- Either more flexible storage on network SSDs (
network-ssd
) or non-replicated SSDs (network-ssd-nonreplicated
). - Or faster local SSD storage (
local-ssd
).
The selected type determines the increments in which you can change your disk size:
- Network SSD storage: In increments of 1 GB.
- Local SSD storage:
- For Intel Broadwell and Intel Cascade Lake: In increments of 100 GB.
- For Intel Ice Lake: In increments of 368 GB.
- Non-replicated SSD storage: In increments of 93 GB.
- Either more flexible storage on network SSDs (
-
Select the storage size. The available storage size is limited by quotas and limits.
-
-
Under Cluster configuration, in the Password field, set the user password.
The password must be between 8 and 128 characters long. The password must meet the
[a-zA-Z0-9@=+?*.,!&#$^<>_-]*
regular expression. -
Under Network settings, select:
- Cloud network for the cluster.
- Security groups for the cluster network traffic. You may also need to set up security groups to connect to the cluster.
-
Under Hosts:
-
To change the settings of a host, click the
- Availability zone: Select an availability zone.
- Subnet: Specify a subnet in the selected availability zone.
- Public access: Enable access to the host from the internet if the cluster is created with TLS support activated.
- Shard name: Enables you to change the shard name for the host. The field is only available if the cluster is created with the enabled Cluster sharding setting.
-
To add hosts to the cluster, click Add host.
-
-
Configure additional cluster settings, if required:
-
Backup start time (UTC): UTC time when you want to start creating a cluster backup (in 24-hour format). If the time is not set, the backup will start at 22:00 UTC.
-
Maintenance window: Maintenance window settings:
- To enable maintenance at any time, select arbitrary (default).
- To specify the preferred maintenance start time, select by schedule and specify the desired day of the week and UTC hour. For example, you can choose a time when the cluster is least loaded.
Maintenance operations are carried out both on enabled and disabled clusters. They may include updating the DBMS, applying patches, and so on.
-
Deletion protection: Manages cluster protection from accidental deletion by a user.
Cluster deletion protection will not prevent a manual connection to delete the contents of a database.
-
-
Configure the DBMS settings, if required.
-
Click Create cluster.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To create a cluster:
-
Check whether the folder has any subnets for the cluster hosts:
yc vpc subnet list
If there are no subnets in the folder, create the required subnets in VPC.
-
View a description of the create cluster CLI command:
yc managed-redis cluster create --help
-
When you create a cluster from the CLI, you cannot explicitly specify the host type and amount of RAM. Choose the applicable host class instead. To see what host classes are available, run the command:
yc managed-redis resource-preset list
-
Specify the cluster parameters in the create command (only some of the supported flags are given in the example):
yc managed-redis cluster create \ --name <cluster_name> \ --environment <environment> \ --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 \ --resource-preset <host_class> \ --disk-size <storage_size_in_GB> \ --password=<user_password> \ --backup-window-start <time> \ --deletion-protection=<deletion_protection>
Where:
-
--environment
:prestable
orproduction
. -
--host
: Host parameters:zone-id
: Availability zone.subnet-id
: Subnet ID. Specify if two or more subnets are created in the selected availability zone.assign-public-ip
: Flag enabling online access to the host by a public IP,true
orfalse
.replica-priority
: Priority for selecting the host as a master if the primary master fails.
-
--backup-window-start
: Backup start time inHH:MM:SS
format. -
--deletion-protection
: Cluster deletion protection,true
orfalse
.
You need to specify the
subnet-id
if the selected availability zone has two or more subnets.The password must be between 8 and 128 characters long. The password must meet the
[a-zA-Z0-9@=+?*.,!&#$^<>_-]*
regular expression.Cluster deletion protection will not prevent a manual connection to delete the contents of a database.
Note
When creating a cluster, the
anytime
maintenance mode is set by default. You can set a specific maintenance period when updating the cluster settings. -
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To create a cluster:
-
In the configuration file, describe the parameters of the resources you want to create:
-
Database cluster: Description of the cluster and its hosts. You can also configure DBMS settings here if necessary.
-
Network: Description of the cloud network where the cluster will be hosted. If you already have a suitable network, you do not need to describe it again.
-
Subnets: Subnets to connect the cluster hosts to. If you already have suitable subnets, you do not need to describe them again.
Sample configuration file structure for creating sharded clusters with SSL support:
resource "yandex_mdb_redis_cluster" "<cluster_name>" { name = "<cluster_name>" environment = "<environment>" network_id = "<network_ID>" security_group_ids = [ "<list_of_security_group_IDs>" ] tls_enabled = true deletion_protection = <deletion_protection> config { password = "<password>" version = "<Redis_version>" } resources { resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_in_GB> } host { 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
orPRODUCTION
.deletion_protection
: Cluster deletion protection,true
orfalse
.version
: Redis version, 6.2 or 7.0.host
: Host parameters:zone_id
: Availability zone.subnet_id
: ID of a subnet in the selected availability zone.assign_public_ip
: Public access to the host,true
orfalse
.replica_priority
: Host priority.
The password must be between 8 and 128 characters long. The password must meet the
[a-zA-Z0-9@=+?*.,!&#$^<>_-]*
regular expression.Cluster deletion protection will not prevent a manual connection to delete the contents of a database.
To set up the maintenance window (for example, for disabled clusters), add the
maintenance_window
section to the cluster description:resource "yandex_mdb_redis_cluster" "<cluster_name>" { ... maintenance_window { type = <maintenance_type> day = <day_of_week> hour = <hour> } ... }
Where:
type
: Maintenance type. The possible values include:anytime
: Anytime.weekly
: By schedule.
day
: Day of the week for theweekly
type inDDD
format, e.g.,MON
.hour
: Hour of the day for theweekly
type in theHH
format, e.g.,21
.
For more information on resources that you can create with Terraform, see the provider documentation
. -
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Create a cluster.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
After this, all required resources will be created in the specified folder, and the FQDNs of the cluster hosts will be displayed in the terminal. You can check the new resources and their configuration using the management console
.Time limits
A Terraform provider sets the timeout for Managed Service for Redis cluster operations:
- Creating a cluster, including by restoring one from a backup: 15 minutes.
- Editing a cluster: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?Add the
timeouts
block to the cluster description, for example:resource "yandex_mdb_redis_cluster" "<cluster_name>" { ... timeouts { create = "1h30m" # 1 hour 30 minutes update = "2h" # 2 hours delete = "30m" # 30 minutes } }
-
To create a Redis cluster, use the create REST API method for the Cluster resource or the ClusterService/Create gRPC API call and provide the following in the request:
- ID of the folder where the cluster should be placed, in the
folderId
parameter. - Cluster name in the
name
parameter. - Security group IDs in the
securityGroupIds
parameter. tlsEnabled=true
flag for creating clusters with encrypted SSL support.- Settings of public access to hosts in the
hostSpecs[].assignPublicIp
parameter.
Warning
If you specified security group IDs when creating a cluster, you may also need to configure security groups to connect to the cluster.
Examples
Creating a single-host cluster
To create a cluster with a single host, provide a single --host
parameter.
Create a Managed Service for Redis cluster with the following test characteristics:
- Name:
myredis
- Version:
7.0
- Environment:
production
- Network:
default
- Single
hm1.nano
host in theb0rcctk2rvtr********
subnet in theru-central1-a
availability zone and security group with theenp6saqnq4ie244g67sb
ID with public access and a host priority of50
. - SSL support: Enabled
- Network SSD storage (
network-ssd
): 16 GB - Password:
user1user1
- Protection against accidental cluster deletion: Enabled
Run the following command:
yc managed-redis cluster create \
--name myredis \
--redis-version 7.0 \
--environment production \
--network-name default \
--resource-preset hm1.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=true
Create a Managed Service for Redis cluster and a network for it with the following test characteristics:
- Name:
myredis
- Version:
7.0
- Environment:
PRODUCTION
- Cloud ID:
b1gq90dgh25bebiu75o
- Folder ID:
b1gia87mbaomkfvsleds
- New network:
mynet
- Single
s2.micro
host in a new subnet namedmysubnet
in theru-central1-a
availability zone with public access and a host priority of50
. Themysubnet
subnet will have the10.5.0.0/24
range. - In the new
redis-sg
security group allowing connections through port6380
from any addresses in themysubnet
subnet. - SSL support: Enabled
- Network SSD storage (
network-ssd
): 16 GB - Password:
user1user1
- Protection against accidental cluster deletion: Enabled
The configuration file for this cluster is as follows:
resource "yandex_mdb_redis_cluster" "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 = "7.0"
}
resources {
resource_preset_id = "s2.micro"
disk_type_id = "network-ssd"
disk_size = 16
}
host {
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 = "Redis"
port = 6380
protocol = "TCP"
v4_cidr_blocks = ["10.5.0.0/24"]
}
egress {
description = "Redis"
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"]
}
Creating sharded clusters
Create a sharded Managed Service for Redis cluster with the following test characteristics:
- Name:
myredis
- Version:
7.0
- Environment:
PRODUCTION
- Cloud ID:
b1gq90dgh25bebiu75o
- Folder ID:
b1gia87mbaomkfvsleds
- New network:
mynet
- Three subnets in the
mynet
network, one in each availability zone:subnet-a
with the10.1.0.0/24
range.subnet-b
with the10.2.0.0/24
range.subnet-d
with the10.3.0.0/24
range.
- Three
s2.micro
hosts, one in each subnet. - In the new
redis-sg
security group allowing connections through ports6379
and26379
(Redis Sentinel) from any subnet address. - Network SSD storage (
network-ssd
): 16 GB - Password:
user1user1
- Protection against accidental cluster deletion: Enabled
The configuration file for this cluster is as follows:
resource "yandex_mdb_redis_cluster" "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 = "7.0"
}
resources {
resource_preset_id = "s2.micro"
disk_type_id = "network-ssd"
disk_size = 16
}
host {
zone = "ru-central1-a"
subnet_id = yandex_vpc_subnet.subnet-a.id
shard_name = "shard1"
}
host {
zone = "ru-central1-b"
subnet_id = yandex_vpc_subnet.subnet-b.id
shard_name = "shard2"
}
host {
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 = "Redis"
port = 6379
protocol = "TCP"
v4_cidr_blocks = [
"10.1.0.0/24",
"10.2.0.0/24",
"10.3.0.0/24"
]
}
egress {
description = "Redis"
port = 6379
protocol = "TCP"
v4_cidr_blocks = [
"10.1.0.0/24",
"10.2.0.0/24",
"10.3.0.0/24"
]
}
ingress {
description = "Redis Sentinel"
port = 26379
protocol = "TCP"
v4_cidr_blocks = [
"10.1.0.0/24",
"10.2.0.0/24",
"10.3.0.0/24"
]
}
egress {
description = "Redis Sentinel"
port = 26379
protocol = "TCP"
v4_cidr_blocks = [
"10.1.0.0/24",
"10.2.0.0/24",
"10.3.0.0/24"
]
}
}