Configuring Yandex Cloud DNS to access a Yandex Managed Service for ClickHouse® cluster from other cloud networks
In this tutorial, we will use a Managed Service for ClickHouse® cluster as an example. The process of configuring availability for other managed database services is similar.
Resource records for Managed Service for ClickHouse® clusters are created in DNS service zones operating within a single cloud network. This prevents clients, such as virtual machines residing in a different cloud network, from connecting to cluster hosts using their FQDNs, even with configured network connectivity between the cloud networks.
To enable clients from different cloud networks to connect to the cluster using its FQDN, configure a shared DNS zone in Yandex Cloud DNS:
- Create a zone in Yandex Cloud DNS.
- Check if the the cluster is available from a different cloud network.
If you no longer need the resources you created, delete them.
Getting started
-
Prepare an SSH key pair to connect to VMs.
-
Prepare the infrastructure:
ManuallyUsing Terraform- Create two cloud networks named
mch-net
andanother-net
. - Create a subnet in each network.
- In
mch-net
, create a Managed Service for ClickHouse® cluster of any suitable configuration with hosts that have no public access. - (Optional) In
mch-net
, create a Linux-based VM namedmch-net-vm
. When creating it, specify the public SSH key prepared earlier. - In
another-net
, create a Linux-based VM namedanother-net-vm
. When creating it, specify the public SSH key prepared earlier. - Configure VM and cluster security group rules by following this guide.
-
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
Download the file with provider settings
. Place it in a separate working directory and specify the parameter values. -
Download the nets-vm-mch.tf
configuration file to the same working directory.This file describes:
- Networks.
- Subnets.
- Security groups required for the Managed Service for ClickHouse® cluster and VMs.
- Virtual machines.
- Managed Service for ClickHouse® cluster.
- Internal DNS zone.
-
In the
nets-vm-mch.tf
file, specify:ch_dbname
: Name of the Managed Service for ClickHouse® cluster database.ch_user
: Managed Service for ClickHouse® cluster admin username.ch_password
: Managed Service for ClickHouse® cluster admin user password.image_id
: ID of the VM public image. For more information about how to get a list of available images, see this guide.vm_username
: Virtual machine username.vm_ssh_key_path
: Absolute path to the VM public key you prepared earlier.create_optional_vm
: Parameter for creating a virtual machine in the same network as the cluster. Set it to1
to later check if the cluster is available from the same network (optional).
-
Run the
terraform init
command in the directory with the configuration files. This command initializes the provider specified in the configuration file and enables you to use the provider resources and data sources. -
Make sure the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
Create the required infrastructure:
-
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.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
. -
- Create two cloud networks named
-
(Optional) Use SSH to connect to the
mch-net-vm
virtual machine and configure cluster connection viaclickhouse-client
to make sure security groups are configured correctly and you can connect to the cluster using its FQDN from the same cloud network. -
Configure network connectivity between the
mch-net
andanother-net
networks, for example, using an IPSec gateway. For other ways to configure network connectivity, see Tutorials for working with network infrastructure in Yandex Cloud.
Create a zone in Cloud DNS
-
Create a DNS zone:
ManuallyUsing TerraformCreate a private DNS zone with the
mdb.yandexcloud.net.
address by following this guide. In the network list, specifymch-net
andanother-net
.-
In the
nets-vm-mch.tf
file, set thecreate_zone
parameter to1
. -
Make sure the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
Create the required infrastructure:
-
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.
-
-
-
-
Make sure the cluster record appears automatically in the DNS zone.
- In the management console
, select the folder containing the DNS zone. - Select Cloud DNS.
- Select the zone from the list.
- Check that the record list includes a record in the following format:
c-<cluster_ID>.rw.mdb.yandexcloud.net.
.
- In the management console
Check whether the cluster is available from a different cloud network
- Use SSH to connect to the
another-net-vm
virtual machine. - Configure cluster connection via
clickhouse-client
and make sure you can connect to the cluster from a different cloud network using the cluster's FQDN.
Delete the resources you created
Some resources are not free of charge. To avoid paying for them, delete the resources you no longer need:
If you created your resources using Terraform:
-
In the terminal window, go to the directory containing the infrastructure plan.
-
Delete the
nets-vm-mch.tf
configuration file. -
Make sure the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
Confirm updating the resources.
-
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.
-
This will delete all the resources described in the
nets-vm-mch.tf
configuration file. -
ClickHouse® is a registered trademark of ClickHouse, Inc