Set Up Communication for Virtual Machines Using Windows Azure Cmdlets
Updated: December 11, 2012
You can use the Windows Azure cmdlets to setup and configure external communications to a Windows Azure virtual machine. You can communicate with virtual machines by using endpoints. Endpoints are used for both direct connectivity to a virtual machine, such as through RDP or SSH, and for load-balancing traffic to virtual machines. You can use the cmdlets to do the following:
-
Add or remove an endpoint on a virtual machine
-
Add a load balanced endpoint to virtual machines
-
Change the settings of an endpoint on a virtual machine
This section shows you how to add or remove an endpoint to a virtual machine. You can add an endpoint to an existing virtual machine, or add it during the initial deployment of the virtual machine. You can remove an endpoint from an existing virtual machine, or remove a load-balancing endpoint from a virtual machine to remove it from the load-balancing group. Use the following cmdlets to add or remove an endpoint to a virtual machine:
-
Get-AzureVM
-
Add-AzureEndpoint
-
Update-AzureVM
-
New-AzureVMConfig
-
Add-AzureProvisioningConfig
-
New-AzureVM
-
Remove-AzureEndpoint
Before you can use Windows PowerShell to add or remove an endpoint on a virtual machine, you need to:
-
Create a Windows Azure subscription.
-
Create a Windows Azure Storage account for your subscription.
-
Download and install the Windows Azure PowerShell module.
-
Configure a management certificate for the subscription.
-
Configure connectivity to your subscription.
For more information about completing these tasks, see Get Started with Windows Azure Cmdlets.
You can define endpoints that are associated to specific ports and are assigned a specific communication protocol. An endpoint can be assigned a protocol of either TCP or UDP. The TCP protocol includes both HTTP and HTTPS traffic.
Each endpoint defined for a virtual machine is assigned a public port and a local, or private, port for communication. The local port is used for setting up communication rules on the virtual machine, and the public port is used by Windows Azure to communicate with the virtual machine from external sources. Each endpoint must have a distinguishing name.
You can add endpoints to a virtual machine either during initial deployment, or after the virtual machine is deployed.
To add an endpoint to an existing virtual machine, do the following:
-
Get a list of virtual machines and the services that host them. Type:
PS C:\> Get-AzureVM
-
Select the virtual machine and assign the virtual machine object to a variable. For example, to select a virtual machine hosted in the mySvc cloud service and assign it to a variable named $target, type:
PS C:\> $target = Get-AzureVM -ServiceName "mySvc" -Name "myVM01"
-
Add the new endpoint and update the virtual machine. For example, to add a public endpoint, named myEP, on TCP port 8080 that corresponds to a local port of 80, type:
PS C:\> Add-AzureEndpoint -Name "myEP" -Protocol TCP -LocalPort 80 -PublicPort 8080 -VM $target | Update-AzureVM
If you want instruction on using the Windows Azure Management Portal to do this, see How to Set Up Communication with a Virtual Machine.
You can add an endpoint to a virtual machine when you are creating the virtual machine, as long as you use the New-AzureVM cmdlet. The New-AzureQuickVM doesn't support adding an endpoint. To deploy a new virtual machine, complete with endpoint, use the following steps:
-
Get a list of images that you can use to create the virtual machine. Type:
PS C:\> Get-AzureVMImage
-
Select the image name property of the image you want to use to create the virtual machine and assign it to a variable. For example, to select the sixth image and assign it to a variable named $myImg, type:
PS C:\> $myImg = (Get-AzureVMImage)[5].ImageName
-
Get a list of Windows Azure cloud services associated with the current subscription. Type:
PS C:\> Get-AzureService
-
Select the service name property of the cloud service in which you want to host the new virtual machine. For example, to select the first cloud service in the list, type:
PS C:\> $mySvc = (Get-AzureService)[0].ServiceName
-
Create the virtual machine object and assign it to a variable. For example, to assign it to a variable named $vm1, type:
PS C:\> $vm1 = New-AzureVMConfig -ImageName $myImg -Name "myVM1" -InstanceSize "Small"
-
Modify the virtual machine object to specify the operating system and set the password. For example, to specify the Windows Server operating system and set the password for the Administrator account, type:
PS C:\> $vm1 = Add-AzureProvisioningConfig -Windows -VM $vm1 -Password "P@ssw0rd"
-
Add the endpoint to the virtual machine object. Type:
PS C:\> $vm1 = Add-AzureEndpoint -Name "myEP" -Protocol TCP -LocalPort 80 -PublicPort 8080 -VM $vm1
-
Create the virtual machine. Type:
PS C:\> New-AzureVM -ServiceName $mySvc -VMs $vm1
Tip |
|---|
You can combine steps 5-8 into a single pipeline by running a command such as: PS C:\> New-AzureVMConfig -ImageName $myImg -Name "myVM1" -InstanceSize "Small" | Add-AzureProvisioningConfig -Windows -Password "P@ssw0rd" | Add-AzureEndpoint -Name "myEP" -Protocol TCP -LocalPort 80 -PublicPort 8080 | New-AzureVM -ServiceName $mySvc |
For more information about creating a custom virtual machine, see Create or Delete Virtual Machines Using Windows Azure Cmdlets.
By using a pipeline, you can use a single command to remove an endpoint from a virtual machine. For example, to remove an endpoint named myEP from a service named mySvc that runs a virtual machine named myVM, type:
PS C:\> Get-AzureVM -ServiceName "mySvc" -Name "myVM" | Remove-AzureEndpoint -Name "myEP"
Note |
|---|
| If you remove a load-balancing endpoint from a virtual machine, you remove the virtual machine from the load-balancing pool, but do not affect other virtual machines in the pool. |
This section shows you how to add a load-balancing endpoint to a virtual machine. You can add an endpoint to an existing virtual machine, or add it when you create a new virtual machine. Use the following cmdlets to add a load-balancing endpoint to a virtual machine:
-
Get-AzureVM
-
Add-AzureEndpoint
-
Update-AzureVM
-
New-AzureVMConfig
-
Add-AzureProvisioningConfig
-
New-AzureVM
Before you can use Windows PowerShell to a load balanced endpoint to virtual machines, you need to:
-
Create a Windows Azure subscription.
-
Create a Windows Azure Storage account for your subscription.
-
Download and install the Windows Azure PowerShell module.
-
Configure a management certificate for the subscription.
-
Configure connectivity to your subscription.
For more information about completing these tasks, see Get Started with Windows Azure Cmdlets.
You can define endpoints that are associated to specific ports and are assigned a specific communication protocol. An endpoint can be assigned a protocol of either TCP or UDP. The TCP protocol includes both HTTP and HTTPS traffic. When you add a load-balancing endpoint to a virtual machine, you add that virtual machine to the load-balancing set of the same name. Each virtual machine in the load-balancing set shares the same public port and LBSetName as other machines in the load-balancing set.
Each endpoint defined for a virtual machine is assigned a public port and a local, or private, port for communication. The local port is used for setting up communication rules on the virtual machine, and the public port is used by Windows Azure to communicate with the virtual machines in the load-balancing set from external sources. Each load-balancing endpoint must have a distinguishing name and share a common LBSetName with the other virtual machines in the load-balancing set.
Each load-balancing endpoint must also have a probe port and probe protocol. Acceptable probe protocols are 'TCP' and 'HTTP '. If you use HTTP as a probe protocol, you must also define a probe path.
To add a load-balancing endpoint to an existing virtual machine, do the following:
-
Get a list of virtual machines and the services that host them. Type:
PS C:\> Get-AzureVM
-
Select the virtual machine and assign it to a variable. For example, to assign the virtual machine myVM01 running in the mySvc cloud service to a variable named $target, type:
PS C:\> $target = Get-AzureVM -ServiceName "mySvc" -Name "myVM01"
-
Add the new endpoint and update the virtual machine. For example, to add a public endpoint named myEP on TCP port 8080 that corresponds to a local port of 80, and adds the virtual machine to the load-balancing set named webfarm, type:
PS C:\> Add-AzureEndpoint -Name "myEP" -Protocol TCP -LocalPort 80 -PublicPort 8080 -LBSetName "webfarm" -probeprotocol 'http' -probepath '/' -probeport 80 -VM $target | Update-AzureVM
If you want instruction on using the Windows Azure Management Portal to do this, see, Load Balancing Virtual Machines.
You can add a load-balancing endpoint to a virtual machine when you create the virtual machine, if you use the New-AzureVM cmdlet. The New-AzureQuickVM does not support adding an endpoint. To deploy a new virtual machine, complete with load-balancing endpoint, do the following:
-
Get a list of images that you can use to create the virtual machine. Type:
PS C:\> Get-AzureVMImage
-
Select the image name property of the image you want to use to create the virtual machine and assign it to a variable. For example, to select the sixth image and assign it to a variable named $myImg, type:
PS C:\> $myImg = (Get-AzureVMImage)[5].ImageName
-
Get a list of Windows Azure cloud services associated with the current subscription. Type:
PS C:\> Get-AzureService
-
Select the service name property of the cloud service in which you want to host the new virtual machine. For example, to select the first cloud service in the list, type:
PS C:\> $mySvc = (Get-AzureService)[0].ServiceName
-
Create the virtual machine object and assign it to a variable. For example, to assign it to a variable named $vm1, type:
PS C:\> $vm1 = New-AzureVMConfig -ImageName $myImg -Name "myVM1" -InstanceSize "Small"
-
Modify the virtual machine object to specify the operating system and set the password. For example, to specify the Windows Server operating system and set the password for the Administrator account, type:
PS C:\> $vm1 = Add-AzureProvisioningConfig -Windows -VM $vm1 -Password "P@ssw0rd"
-
Add the endpoint to the virtual machine object. Type:
PS C:\> $vm1 = Add-AzureEndpoint -Name "myEP" -Protocol TCP -LocalPort 80 -PublicPort 8080 -LBSetName "webfarm" -ProbeProtocol 'tcp' -ProbePort 80 -VM $vm1
-
Create the virtual machine. Type:
PS C:\> New-AzureVM -ServiceName $mySvc -VMs $vm1
Tip |
|---|
You can combine steps 5-8 into a single pipeline by running a command such as: PS C:\> New-AzureVMConfig -ImageName $myImg -Name "myVM1" -InstanceSize "Small" | Add-AzureProvisioningConfig -Windows -Password "P@ssw0rd" | Add-AzureEndpoint -Name "myEP" -Protocol TCP -LocalPort 80 -PublicPort 8080 -LBSetName "webfarm" -ProbeProtocol 'tcp' -ProbePort 80 | New-AzureVM -ServiceName $mySvc |
This section shows you how to change the settings of a virtual machine endpoint. Use the following cmdlets to change the settings of a virtual machine endpoint:
Before you can use Windows PowerShell to add or remove an endpoint on a virtual machine, you need to:
-
Create a Windows Azure subscription.
-
Create a Windows Azure Storage account for your subscription.
-
Download and install the Windows Azure PowerShell module.
-
Configure a management certificate for the subscription.
-
Configure connectivity to your subscription.
For more information about completing these tasks, see Get Started with Windows Azure Cmdlets.
You can modify the settings for an endpoint on a virtual machine by using the Set-AzureEndpoint cmdlet. This allows you to change the public and local ports of an endpoint dynamically, without having to delete and recreate the endpoint.
You will need to know the virtual machine you are changing the endpoint for and the endpoint name. If the endpoint is a load-balancing endpoint, you can change the protocol, the local port, the probe protocol and the probe path, but you can't change the public port.
If you need to change the public port for a load-balancing set, you can create a new load-balanced set with the new public port, add the virtual machines to the new load-balancing set, and then remove the old endpoints from the virtual machines. When all the virtual machine endpoints of a load-balancing set have been removed, the load-balancing set is removed.
To change the properties of an endpoint to a virtual machine, do the following:
-
Get a list of virtual machines and the cloud services they are hosted on, for the current Windows Azure subscription. Type:
PS C:\> Get-AzureVM
-
Get a list of the endpoints on the target virtual machine. Type:
PS C:\> Get-AzureVM -ServiceName "mySvc" -Name "myVM01" | Get-AzureEndpoint
-
Set the new parameters for the virtual machine. Type:
This command gets the virtual machine configuration object, modifies that configuration object, and then submits the updated configuration to the Update-AzureVM cmdlet, which actually requests Windows Azure to make the change. The result of the change request is returned as an object with properties of OperationDescription, OperationID, and OperationStatus.PS C:\> Get-AzureVM -ServiceName "mySvc" -Name "myVM01" | Set-AzureEndpoint -Name "myEP" -PublicPort 443 -LocalPort 443 -Protocol tcp | Update-AzureVM
Tip
Note