Setting up Yandex Cloud DNS to access managed database clusters 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
- Managed Service for ClickHouse® cluster: use of computing resources allocated to hosts, storage and backup size (see Managed Service for ClickHouse® pricing).
- VM instance: use of computing resources, storage, public IP address, and OS (see Yandex Compute Cloud pricing).
- Public DNS requests and DNS zones (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. In the process, you will need to specify the public SSH key you created earlier. - Configure security group rules for your cluster and VMs according to 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. Instead of manually creating the provider configuration file, you can download it
. -
Place the configuration file in a separate working directory and specify the parameter values. If you have not added 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. If you later need to test the cluster for accessibility from the same network, set it to1.
-
Create the resources:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planThe terminal will display a list of intended changes: resources and/or output variables. No changes will be made at this step. Terraform will show any errors detected in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
-
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
nets-vm-mch.tf, setcreate_zoneto1. -
Create the resources:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planThe terminal will display a list of intended changes: resources and/or output variables. No changes will be made at this step. Terraform will show any errors detected in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
-
-
-
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 Cloud DNS. - Select the zone you created earlier.
- 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
To stop paying for the resources created, delete 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