Configuring Yandex Cloud DNS to access a 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. - Optionally, 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 do not have Terraform yet, install it.
-
Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.
-
Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it
. -
Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.
-
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.
-
Specify the following in the
nets-vm-mch.tf
file:ch_dbname
: Name of the database in the Managed Service for ClickHouse® cluster.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
: VM user name.vm_ssh_key_path
: Absolute path to the VM public key you prepared earlier.create_optional_vm
: Parameter for creating a VM in the same network as the cluster. Optionally, set it to1
so you can later check if the cluster is available from the same network.
-
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. -
Check that 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
-
Optionally, use SSH to connect to the
mch-net-vm
VM 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, e.g., 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 as per this guide. In the network list, specifymch-net
andanother-net
.-
In the
nets-vm-mch.tf
file, set thecreate_zone
parameter to1
. -
Check that 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
VM. - 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:
-
In the terminal window, go to the directory containing the infrastructure plan.
Warning
Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
-
Delete resources:
-
Run this command:
terraform destroy
-
Confirm deleting the resources and wait for the operation to complete.
All the resources described in the Terraform manifests will be deleted.
-
ClickHouse® is a registered trademark of ClickHouse, Inc