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. You can use the same method to configure availability for other managed database services.
Managed Service for ClickHouse® cluster resource records reside in DNS service zones that are confined to one cloud network. This prevents clients, such as virtual machines residing in a different cloud network, from connecting to cluster hosts via FQDN, despite established network connectivity.
To enable clients from different cloud networks to connect to the cluster via FQDN, configure a shared DNS zone in Yandex Cloud DNS:
- Create a zone in Yandex Cloud DNS.
- Check if the cluster is available from a different cloud network.
If you no longer need the resources you created, delete them.
Required paid resources
The support cost for this solution includes:
- Managed Service for ClickHouse® cluster fee: Covers the use of computing resources allocated to hosts (including ZooKeeper hosts) and disk space (see Managed Service for ClickHouse® pricing).
- VM fee: Covers the use of computational resources, storage, and, optionally, a public IP address (see Compute Cloud pricing).
- DNS zone and queries fee (see Cloud DNS pricing).
Getting started
-
Prepare an SSH key pair for connecting to virtual machines.
-
Set up the infrastructure:
ManuallyUsing Terraform- Create two cloud networks named
mch-netandanother-net. - Create a subnet in each network.
- In
mch-net, create a Managed Service for ClickHouse® cluster with no public access for its hosts, using any suitable configuration. - Optionally, in
mch-net, create a Linux-based VM namedmch-net-vm. In the process, you will need to specify the public SSH key you created earlier. - In
another-net, create a Linux-based VM namedanother-net-vm. When creating it, specify the public SSH key you prepared earlier. - Configure security group rules for your cluster and VMs according to this tutorial.
-
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 your current 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.tffile, specify the following:ch_dbname: Managed Service for ClickHouse® cluster database name.ch_user: Managed Service for ClickHouse® cluster admin username.ch_password: Managed Service for ClickHouse® cluster admin password.image_id: VM public image ID. For details on getting a list of available images, see this guide.vm_username: VM user name.vm_ssh_key_path: Absolute path to your previously created VM public key.create_optional_vm: Parameter that enables VM creation in the cluster’s network. Optionally, set it to1to test cluster accessibility from the same network later.
-
Run the
terraform initcommand in the directory with your configuration files. This command initializes the provider specified in the configuration file, making its resources and data sources available for use. -
Validate your Terraform configuration files using this command:
terraform validateTerraform will display any configuration errors detected in your files.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform planIf 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.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the 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, connect to the
mch-net-vmVM over SSH and configure cluster connection usingclickhouse-clientto make sure security groups are configured correctly and you can access the cluster via FQDN from within the cloud network. -
Configure network connectivity between the
mch-netandanother-netcloud networks, e.g., via an IPSec gateway. For alternative methods of configuring network connectivity, see Tutorials on the use of the network infrastructure in Yandex Cloud network infrastructure tutorials.
Create a zone in Cloud DNS
-
Create a DNS zone:
ManuallyUsing TerraformCreate a private DNS zone for
mdb.yandexcloud.net.by following this tutorial, specifyingmch-netandanother-netin the network list.-
In the
nets-vm-mch.tffile, setcreate_zoneto1. -
Validate your Terraform configuration files using this command:
terraform validateTerraform will display any configuration errors detected in your files.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform planIf 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.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
-
-
Verify that the cluster record has been automatically created in the DNS zone.
- In the management console
, select the folder containing your DNS zone. - Navigate to the Cloud DNS service.
- Select the zone from the list.
- Make sure the list contains 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
another-net-vm. - Configure cluster connection using
clickhouse-clientand check whether you can access the cluster via FQDN from a different cloud network.
Delete the resources you created
Some resources are not free of charge. Delete the resources you no longer need to avoid paying for them:
-
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