title | description | author | ms.author | ms.service | ms.topic | ms.date |
---|---|---|---|---|---|---|
Private Link - Azure CLI - Azure Database for MariaDB |
Learn how to configure private link for Azure Database for MariaDB from Azure CLI |
kummanish |
manishku |
mariadb |
conceptual |
01/09/2020 |
A Private Endpoint is the fundamental building block for private link in Azure. It enables Azure resources, like Virtual Machines (VMs), to communicate privately with private link resources. In this article, you will learn how to use the Azure CLI to create a VM in an Azure Virtual Network and an Azure Database for MariaDB server with an Azure private endpoint.
Note
This feature is available in all Azure regions where Azure Database for MariaDB supports General Purpose and Memory Optimized pricing tiers.
To step through this how-to guide, you need:
[!INCLUDE cloud-shell-try-it.md]
If you decide to install and use Azure CLI locally instead, this quickstart requires you to use Azure CLI version 2.0.28 or later. To find your installed version, run az --version
. See Install Azure CLI for install or upgrade info.
Before you can create any resource, you have to create a resource group to host the Virtual Network. Create a resource group with az group create. This example creates a resource group named myResourceGroup in the westeurope location:
az group create --name myResourceGroup --location westeurope
Create a Virtual Network with az network vnet create. This example creates a default Virtual Network named myVirtualNetwork with one subnet named mySubnet:
az network vnet create \
--name myVirtualNetwork \
--resource-group myResourceGroup \
--subnet-name mySubnet
Azure deploys resources to a subnet within a virtual network, so you need to create or update the subnet to disable private endpoint network policies. Update a subnet configuration named mySubnet with az network vnet subnet update:
az network vnet subnet update \
--name mySubnet \
--resource-group myResourceGroup \
--vnet-name myVirtualNetwork \
--disable-private-endpoint-network-policies true
Create a VM with az vm create. When prompted, provide a password to be used as the sign-in credentials for the VM. This example creates a VM named myVm:
az vm create \
--resource-group myResourceGroup \
--name myVm \
--image Win2019Datacenter
Note the public IP address of the VM. You will use this address to connect to the VM from the internet in the next step.
Create a Azure Database for MariaDB with the az mariadb server create command. Remember that the name of your MariaDB Server must be unique across Azure, so replace the placeholder value in brackets with your own unique value:
# Create a server in the resource group
az mariadb server create \
--name mydemoserver \
--resource-group myResourcegroup \
--location westeurope \
--admin-user mylogin \
--admin-password <server_admin_password> \
--sku-name GP_Gen5_2
Note
In some cases the Azure Database for MariaDB and the VNet-subnet are in different subscriptions. In these cases you must ensure the following configurations:
- Make sure that both the subscription has the Microsoft.DBforMariaDB resource provider registered. For more information refer resource-manager-registration
Create a private endpoint for the MariaDB server in your Virtual Network:
az network private-endpoint create \
--name myPrivateEndpoint \
--resource-group myResourceGroup \
--vnet-name myVirtualNetwork \
--subnet mySubnet \
--private-connection-resource-id $(az resource show -g myResourcegroup -n mydemoserver --resource-type "Microsoft.DBforMariaDB/servers" --query "id") \
--group-id mysqlServer \
--connection-name myConnection
Create a Private DNS Zone for MariDB server domain and create an association link with the Virtual Network.
az network private-dns zone create --resource-group myResourceGroup \
--name "privatelink.mariadb.database.azure.com"
az network private-dns link vnet create --resource-group myResourceGroup \
--zone-name "privatelink.mariadb.database.azure.com"\
--name MyDNSLink \
--virtual-network myVirtualNetwork \
--registration-enabled false
#Query for the network interface ID
networkInterfaceId=$(az network private-endpoint show --name myPrivateEndpoint --resource-group myResourceGroup --query 'networkInterfaces[0].id' -o tsv)
az resource show --ids $networkInterfaceId --api-version 2019-04-01 -o json
# Copy the content for privateIPAddress and FQDN matching the Azure database for MariaDB name
#Create DNS records
az network private-dns record-set a create --name mydemoserver --zone-name privatelink.mariadb.database.azure.com --resource-group myResourceGroup
az network private-dns record-set a add-record --record-set-name mydemoserver --zone-name privatelink.mariadb.database.windows.net --resource-group myResourceGroup -a <Private IP Address>
Note
The FQDN in the customer DNS setting does not resolve to the private IP configured. You will have to setup a DNS zone for the configured FQDN as shown here.
Connect to the VM myVm from the internet as follows:
-
In the portal's search bar, enter myVm.
-
Select the Connect button. After selecting the Connect button, Connect to virtual machine opens.
-
Select Download RDP File. Azure creates a Remote Desktop Protocol (.rdp) file and downloads it to your computer.
-
Open the downloaded.rdp file.
-
If prompted, select Connect.
-
Enter the username and password you specified when creating the VM.
[!NOTE] You may need to select More choices > Use a different account, to specify the credentials you entered when you created the VM.
-
-
Select OK.
-
You may receive a certificate warning during the sign-in process. If you receive a certificate warning, select Yes or Continue.
-
Once the VM desktop appears, minimize it to go back to your local desktop.
-
In the Remote Desktop of myVM, open PowerShell.
-
Enter
nslookup mydemoserver.privatelink.mariadb.database.azure.com
.You'll receive a message similar to this:
Server: UnKnown Address: 168.63.129.16 Non-authoritative answer: Name: mydemoserver.privatelink.mariadb.database.azure.com Address: 10.1.3.4
-
Test the private link connection for the MariaDB server using any available client. In the example below I have used MySQL Workbench to do the operation.
-
In New connection, enter or select this information:
Setting Value Connection Name Select the connection name of your choice. Hostname Select mydemoserver.privatelink.mariadb.database.azure.com Username Enter username as username@servername which is provided during the MariaDB server creation. Password Enter a password provided during the MariaDB server creation. -
Select Test Connection or OK.
-
(Optionally) Browse databases from left menu and Create or query information from the MariaDB database
-
Close the remote desktop connection to myVm.
When no longer needed, you can use az group delete to remove the resource group and all the resources it has:
az group delete --name myResourceGroup --yes
Learn more about What is Azure private endpoint