Quickstart: Een Private Link-service maken met behulp van Azure PowerShell

Aan de slag met een Private Link-service die naar uw service verwijst. Geef Private Link toegang tot uw service of resource die achter een Azure Standard Load Balancer is geïmplementeerd. Gebruikers van uw service hebben persoonlijke toegang via hun virtuele netwerk.

Snelstart voor een diagram van resources die zijn gemaakt in een privé-eindpunt.

Vereisten

  • Een Azure-account met een actief abonnement. Gratis een account maken

  • Azure Cloud Shell of Azure PowerShell.

    Met de stappen in deze quickstart worden de Azure PowerShell-cmdlets interactief uitgevoerd in Azure Cloud Shell. Als u de opdrachten in de Cloud Shell wilt uitvoeren, selecteert u Cloudshell openen in de rechterbovenhoek van een codeblok. Selecteer Kopiëren om de code te kopiëren en plak deze vervolgens in Cloud Shell om deze uit te voeren. U kunt de Cloud Shell ook uitvoeren vanuit de Azure Portal.

    U kunt Azure PowerShell ook lokaal installeren om de cmdlets uit te voeren. Voor de stappen in dit artikel is Azure PowerShell moduleversie 5.4.1 of hoger vereist. Voer uit Get-Module -ListAvailable Az om de geïnstalleerde versie te vinden. Zie De Azure PowerShell-module bijwerken als u een upgrade moet uitvoeren.

    Als u PowerShell lokaal uitvoert, voert u uit Connect-AzAccount om verbinding te maken met Azure.

Een resourcegroep maken

Een Azure-resourcegroep is een logische container waarin Azure-resources worden geïmplementeerd en beheerd.

Maak een resourcegroep met New-AzResourceGroup:

New-AzResourceGroup -Name 'test-rg' -Location 'eastus2'

Een interne load balancer maken

In deze sectie maakt u een virtueel netwerk en een interne Azure Load Balancer.

Virtueel netwerk

In dit gedeelte maakt u een virtueel netwerk en een subnet om de load balancer te hosten die toegang heeft tot uw Private Link-service.

## Create backend subnet config ##
$subnet = @{
    Name = 'subnet-1'
    AddressPrefix = '10.0.0.0/24'
}
$subnetConfig = New-AzVirtualNetworkSubnetConfig @subnet 

## Create the virtual network ##
$net = @{
    Name = 'vnet-1'
    ResourceGroupName = 'test-rg'
    Location = 'eastus2'
    AddressPrefix = '10.0.0.0/16'
    Subnet = $subnetConfig
}
$vnet = New-AzVirtualNetwork @net

Een Standard Load Balancer maken

In deze sectie wordt beschreven hoe u de volgende onderdelen van de load balancer kunt maken en configureren:

## Place virtual network created in previous step into a variable. ##
$vnet = Get-AzVirtualNetwork -Name 'vnet-1' -ResourceGroupName 'test-rg'

## Create load balancer frontend configuration and place in variable. ##
$lbip = @{
    Name = 'frontend'
    PrivateIpAddress = '10.0.0.4'
    SubnetId = $vnet.subnets[0].Id
}
$feip = New-AzLoadBalancerFrontendIpConfig @lbip

## Create backend address pool configuration and place in variable. ##
$bepool = New-AzLoadBalancerBackendAddressPoolConfig -Name 'backend-pool'

## Create the health probe and place in variable. ##
$probe = @{
    Name = 'health-probe'
    Protocol = 'http'
    Port = '80'
    IntervalInSeconds = '360'
    ProbeCount = '5'
    RequestPath = '/'
}
$healthprobe = New-AzLoadBalancerProbeConfig @probe

## Create the load balancer rule and place in variable. ##
$lbrule = @{
    Name = 'http-rule'
    Protocol = 'tcp'
    FrontendPort = '80'
    BackendPort = '80'
    IdleTimeoutInMinutes = '15'
    FrontendIpConfiguration = $feip
    BackendAddressPool = $bePool
}
$rule = New-AzLoadBalancerRuleConfig @lbrule -EnableTcpReset

## Create the load balancer resource. ##
$loadbalancer = @{
    ResourceGroupName = 'test-rg'
    Name = 'load-balancer'
    Location = 'eastus2'
    Sku = 'Standard'
    FrontendIpConfiguration = $feip
    BackendAddressPool = $bePool
    LoadBalancingRule = $rule
    Probe = $healthprobe
}
New-AzLoadBalancer @loadbalancer

Netwerkbeleid uitschakelen

Voordat een private link-service kan worden gemaakt in het virtuele netwerk, moet de instelling privateLinkServiceNetworkPolicies worden uitgeschakeld.

## Place the subnet name into a variable. ##
$subnet = 'subnet-1'

## Place the virtual network configuration into a variable. ##
$net = @{
    Name = 'vnet-1'
    ResourceGroupName = 'test-rg'
}
$vnet = Get-AzVirtualNetwork @net

## Set the policy as disabled on the virtual network. ##
($vnet | Select -ExpandProperty subnets | Where-Object {$_.Name -eq $subnet}).privateLinkServiceNetworkPolicies = "Disabled"

## Save the configuration changes to the virtual network. ##
$vnet | Set-AzVirtualNetwork

Maak in deze sectie een private link-service die gebruikmaakt van de Standard-Azure Load Balancer die u in de vorige stap hebt gemaakt.

## Place the virtual network into a variable. ##
$vnet = Get-AzVirtualNetwork -Name 'vnet-1' -ResourceGroupName 'test-rg'

## Create the IP configuration for the private link service. ##
$ipsettings = @{
    Name = 'ipconfig-1'
    PrivateIpAddress = '10.0.0.5'
    Subnet = $vnet.subnets[0]
}
$ipconfig = New-AzPrivateLinkServiceIpConfig @ipsettings

## Place the load balancer frontend configuration into a variable. ##
$par = @{
    Name = 'load-balancer'
    ResourceGroupName = 'test-rg'
}
$fe = Get-AzLoadBalancer @par | Get-AzLoadBalancerFrontendIpConfig

## Create the private link service for the load balancer. ##
$privlinksettings = @{
    Name = 'private-link-service'
    ResourceGroupName = 'test-rg'
    Location = 'eastus2'
    LoadBalancerFrontendIpConfiguration = $fe
    IpConfiguration = $ipconfig
}
New-AzPrivateLinkService @privlinksettings

Uw Private Link-service wordt gemaakt en kan verkeer ontvangen. Als u verkeersstromen wilt zien, configureert u uw toepassing achter uw standaard load balancer.

Privé-eindpunt maken

In deze sectie wijst u de Private Link-service toe aan een privé-eindpunt. Een virtueel netwerk bevat het privé-eindpunt voor de private link-service. Dit virtuele netwerk bevat de resources die toegang hebben tot uw Private Link-service.

Virtueel privé-eindpuntnetwerk maken

## Create backend subnet config ##
$subnet = @{
    Name = 'subnet-pe'
    AddressPrefix = '10.1.0.0/24'
}
$subnetConfig = New-AzVirtualNetworkSubnetConfig @subnet 

## Create the virtual network ##
$net = @{
    Name = 'vnet-pe'
    ResourceGroupName = 'test-rg'
    Location = 'eastus2'
    AddressPrefix = '10.1.0.0/16'
    Subnet = $subnetConfig
}
$vnetpe = New-AzVirtualNetwork @net

Eindpunt en verbinding maken

## Place the private link service configuration into variable. ##
$par1 = @{
    Name = 'private-link-service'
    ResourceGroupName = 'test-rg'
}
$pls = Get-AzPrivateLinkService @par1

## Create the private link configuration and place in variable. ##
$par2 = @{
    Name = 'connection-1'
    PrivateLinkServiceId = $pls.Id
}
$plsConnection = New-AzPrivateLinkServiceConnection @par2

## Place the virtual network into a variable. ##
$par3 = @{
    Name = 'vnet-pe'
    ResourceGroupName = 'test-rg'
}
$vnetpe = Get-AzVirtualNetwork @par3

## Create private endpoint ##
$par4 = @{
    Name = 'private-endpoint'
    ResourceGroupName = 'test-rg'
    Location = 'eastus2'
    Subnet = $vnetpe.subnets[0]
    PrivateLinkServiceConnection = $plsConnection
}
New-AzPrivateEndpoint @par4 -ByManualRequest

De privé-eindpuntverbinding goedkeuren

In deze sectie keurt u de verbinding goed die u in de vorige stappen hebt gemaakt.

## Place the private link service configuration into variable. ##
$par1 = @{
    Name = 'private-link-service'
    ResourceGroupName = 'test-rg'
}
$pls = Get-AzPrivateLinkService @par1

$par2 = @{
    Name = $pls.PrivateEndpointConnections[0].Name
    ServiceName = 'private-link-service'
    ResourceGroupName = 'test-rg'
    Description = 'Approved'
    PrivateLinkResourceType = 'Microsoft.Network/privateLinkServices'
}
Approve-AzPrivateEndpointConnection @par2

IP-adres van privé-eindpunt

In deze sectie vindt u het IP-adres van het privé-eindpunt dat overeenkomt met de load balancer en private link-service.

## Get private endpoint and the IP address and place in a variable for display. ##
$par1 = @{
    Name = 'private-endpoint'
    ResourceGroupName = 'test-rg'
    ExpandResource = 'networkinterfaces'
}
$pe = Get-AzPrivateEndpoint @par1

## Display the IP address by expanding the variable. ##
$pe.NetworkInterfaces[0].IpConfigurations[0].PrivateIpAddress
❯ $pe.NetworkInterfaces[0].IpConfigurations[0].PrivateIpAddress
10.1.0.4

Resources opschonen

U kunt de opdracht Remove-AzResourceGroup gebruiken om de resourcegroep, de load balancer en de resterende resources te verwijderen wanneer u deze niet meer nodig hebt.

Remove-AzResourceGroup -Name 'test-rg'

Volgende stappen

In deze snelstart, gaat u het volgende doen:

  • Een virtueel netwerk gemaakt en een interne Azure Load Balancer.

  • Een Private Link-service gemaakt

Voor meer informatie over Azure Privé-eindpunt gaat u naar: