Add a BYOC VNet Peering Connection on Azure
A VNet peering connection is a networking connection between two Azure virtual networks (VNets). Resources in peered VNets communicate with each other over the Microsoft backbone network using private IP addresses, as if they were in the same network.
To let clients in your own VNet produce to and consume from a BYOC cluster with private connectivity, peer your VNet with the Redpanda VNet. Because a BYOC cluster runs in your Azure subscription, you create both sides of the peering yourself.
| Azure charges for data transfer over a VNet peering, in both directions. For high-throughput workloads, consider a BYOVNet cluster. See Network Design and Ports. |
After reading this page, you will be able to:
-
Find the Redpanda VNet for a BYOC cluster on Azure
-
Create a VNet peering connection in both directions with Terraform or the Azure CLI
-
Verify that clients in your VNet can connect to the cluster
Prerequisites
-
A running BYOC cluster on Azure with private connectivity. See Create a BYOC Cluster on Azure.
-
An Azure VNet for your clients. Its address space must not overlap the Redpanda network CIDR (Classless Inter-Domain Routing) range. Azure rejects VNet peering when address spaces overlap. See Choose CIDR Ranges.
-
The Network Contributor role, or a custom role with the
Microsoft.Network/virtualNetworks/virtualNetworkPeerings/writeandMicrosoft.Network/virtualNetworks/peer/actionpermissions, on both VNets. -
Azure CLI or Terraform, authenticated to the subscription that contains the cluster.
Find the Redpanda VNet
Redpanda creates the cluster VNet in your subscription. The VNet is named vnet-rpcloud-<region>-<redpanda-network-id>, and it is in the resource group rg-rpcloud-<redpanda-cluster-id>-network.
-
Find the Redpanda network ID. On your cluster’s Overview page, click Manage network on the Private network card to open the Redpanda network page. The network ID looks similar to the cluster ID, but it is a different value.
-
Get the resource ID of the Redpanda VNet:
az network vnet list \ --query "[?contains(name, '<redpanda-network-id>')].id | [0]" \ --output tsvThe resource ID has the following form:
/subscriptions/<subscription-id>/resourceGroups/rg-rpcloud-<redpanda-cluster-id>-network/providers/Microsoft.Network/virtualNetworks/vnet-rpcloud-<region>-<redpanda-network-id>
Create the peering connection
A VNet peering connection has two peerings, one in each direction. The connection carries traffic only after both peerings exist. Each peering can take a few minutes to create. Azure adds the routes between the two address spaces, so you don’t create routes yourself.
-
Terraform
-
Azure CLI
Add the following to your Terraform configuration, then run terraform apply:
variable "redpanda_vnet_id" {
type = string
description = "Resource ID of the Redpanda VNet."
}
variable "client_resource_group" {
type = string
description = "Resource group of your VNet."
}
variable "client_vnet_name" {
type = string
description = "Name of your VNet."
}
locals {
redpanda_resource_group = split("/", var.redpanda_vnet_id)[4]
redpanda_vnet_name = split("/", var.redpanda_vnet_id)[8]
}
data "azurerm_virtual_network" "client" {
name = var.client_vnet_name
resource_group_name = var.client_resource_group
}
resource "azurerm_virtual_network_peering" "client_to_redpanda" {
name = "client-to-redpanda"
resource_group_name = var.client_resource_group
virtual_network_name = var.client_vnet_name
remote_virtual_network_id = var.redpanda_vnet_id
allow_virtual_network_access = true
}
resource "azurerm_virtual_network_peering" "redpanda_to_client" {
name = "redpanda-to-client"
resource_group_name = local.redpanda_resource_group
virtual_network_name = local.redpanda_vnet_name
remote_virtual_network_id = data.azurerm_virtual_network.client.id
allow_virtual_network_access = true
}
-
Set the following variables:
REDPANDA_VNET_ID="<redpanda-vnet-resource-id>" REDPANDA_RESOURCE_GROUP="rg-rpcloud-<redpanda-cluster-id>-network" REDPANDA_VNET_NAME="vnet-rpcloud-<region>-<redpanda-network-id>" CLIENT_RESOURCE_GROUP="<client-resource-group>" CLIENT_VNET_NAME="<client-vnet-name>" CLIENT_VNET_ID=$(az network vnet show \ --resource-group "$CLIENT_RESOURCE_GROUP" \ --name "$CLIENT_VNET_NAME" \ --query id --output tsv) -
Create the peering from your VNet to the Redpanda VNet:
az network vnet peering create \ --name client-to-redpanda \ --resource-group "$CLIENT_RESOURCE_GROUP" \ --vnet-name "$CLIENT_VNET_NAME" \ --remote-vnet "$REDPANDA_VNET_ID" \ --allow-vnet-access -
Create the peering from the Redpanda VNet to your VNet:
az network vnet peering create \ --name redpanda-to-client \ --resource-group "$REDPANDA_RESOURCE_GROUP" \ --vnet-name "$REDPANDA_VNET_NAME" \ --remote-vnet "$CLIENT_VNET_ID" \ --allow-vnet-access
Verify the peering connection
Check that both peerings report the Connected state:
az network vnet peering list \
--resource-group <client-resource-group> \
--vnet-name <client-vnet-name> \
--query "[].{name:name, state:peeringState, sync:peeringSyncLevel}" \
--output table
az network vnet peering list \
--resource-group rg-rpcloud-<redpanda-cluster-id>-network \
--vnet-name vnet-rpcloud-<region>-<redpanda-network-id> \
--query "[].{name:name, state:peeringState, sync:peeringSyncLevel}" \
--output table
A peering in the Initiated state means the peering in the opposite direction does not exist yet.
Test your connection
Cluster hostnames resolve through public DNS to private IP addresses in the Redpanda network CIDR. You don’t need to configure DNS in your VNet.
From a virtual machine (VM) in your VNet, confirm that the cluster’s bootstrap server resolves to a private IP address and accepts connections:
nc -vz <bootstrap-server-hostname> 9092
Without the peering connection, this command times out. With it, the connection succeeds.
Then follow the directions in the How to connect panel on your cluster’s Overview page to produce and consume messages.
Delete the peering connection
Delete both peerings. If you delete only one, the other stays in the Disconnected state. You must delete and re-create it before the two VNets can be peered again.
-
Terraform
-
Azure CLI
Remove the two azurerm_virtual_network_peering resources from your configuration, then run terraform apply.
If you use a new shell, first set the variables from Create the peering connection.
az network vnet peering delete \
--name client-to-redpanda \
--resource-group "$CLIENT_RESOURCE_GROUP" \
--vnet-name "$CLIENT_VNET_NAME"
az network vnet peering delete \
--name redpanda-to-client \
--resource-group "$REDPANDA_RESOURCE_GROUP" \
--vnet-name "$REDPANDA_VNET_NAME"
Delete the peering connection before you delete the cluster. Deleting the cluster deletes the Redpanda VNet. The peering in your VNet then stays in the Disconnected state, and you must delete it yourself.