Edit

Share via


Create and deploy VM Application

VM Application are a resource type in Azure Compute Gallery that simplifies management, sharing, and global distribution of applications for your virtual machines. Learn more about VM Application

Prerequisites

  1. Create Azure Compute Gallery for storing and sharing application resources.
  2. Upload your application to a container in an Azure storage account. Your application can be stored in a block or page blob. If you choose to use a page blob, you need to byte align the files before you upload them. Use the following sample to byte align your file.
$inputFile = <the file you want to pad>

$fileInfo = Get-Item -Path $inputFile

$remainder = $fileInfo.Length % 512

if ($remainder -ne 0){

    $difference = 512 - $remainder

    $bytesToPad = [System.Byte[]]::CreateInstance([System.Byte], $difference)

    Add-Content -Path $inputFile -Value $bytesToPad -Encoding Byte
    }

Ensure the storage account has public level access or use an SAS URI with read privilege, as other restriction levels fail deployments. You can use Storage Explorer to quickly create a SAS URI if you don't already have one.

If you're using PowerShell, you need to be using version 3.11.0 of the Az.Storage module.

To learn more about the installation mechanism, see the command interpreter.

Create the VM Application

  1. Go to the Azure portal, then search for and select Azure Compute Gallery.
  2. Select the gallery you want to use from the list.
  3. On the page for your gallery, select Add from the top of the page and then select VM application definition from the drop-down. The Create a VM application definition page opens.
  4. In the Basics tab, enter a name for your application and choose whether the application is for VMs running Linux or Windows.
  5. Select the Publishing options tab if you want to specify any of the following optional settings for your VM Application definition:
    • A description of the VM Application definition.
    • End of life date
    • Link to an End User License Agreement (EULA)
    • URI of a privacy statement
    • URI for release notes
  6. When you're done, select Review + create.
  7. When validation completes, select Create to have the definition deployed.
  8. Once the deployment is complete, select Go to resource.
  9. On the page for the application, select Create a VM application version. The Create a VM Application Version page opens.
  10. Enter a version number like 1.0.0.
  11. Select the region where your application packages are uploaded.
  12. Under Source application package, select Browse. Select the storage account, then the container where your package is located. Select the package from the list and then select Select when you're done. Alternatively, you can paste the SAS URI in this field if preferred.
  13. Provide the 'Install script'. You can also provide the 'Uninstall script' and the 'Update script'. See the Overview for information on how to create the scripts.
  14. If you have a default configuration file uploaded to a storage account, you can select it in Default configuration.
  15. Select Exclude from latest if you don't want this version to appear as the latest version when you create a VM.
  16. For End of life date, choose a date in the future to track when this version should be retired. It isn't deleted or removed automatically, it's only for your own tracking.
  17. To replicate this version to other regions, select the Replication tab, add more regions, and make changes to the number of replicas per region. The original region where your version was created must be in the list and can't be removed.
  18. When you're done making changes, select Review + create at the bottom of the page.
  19. When validation shows as passed, select Create to deploy your VM application version.

Deploy the VM Apps

Now you can create a VM and deploy the VM application to it using the portal. Just create the VM as usual, and under the Advanced tab, choose Select a VM application to install.

Screenshot of the Advanced tab where you can choose to install a VM application.

Select the VM application from the list and then select Save at the bottom of the page.

Screenshot showing selecting a VM application to install on the VM.

If you have more than one VM application to install, you can set the install order for each VM application back on the Advanced tab.

You can also deploy the VM application to currently running VMs. Select the Extensions + applications option under Settings in the left menu when viewing the VM details in the portal.

Choose VM applications and then select Add application to add your VM application.

Screenshot showing selecting a VM application to install on a currently running VM.

Select the VM application from the list and then select Save at the bottom of the page.

Screenshot showing selecting a VM application to install on the VM.

Monitor the deployed VM Applications

To show the VM application status, go to the Extensions + applications tab/settings and check the status of the VMAppExtension:

Screenshot showing VM application status.

To show the VM application status for scale set, go to the Azure portal Virtual Machine Scale Sets page, then the Instances section, select one of the scales sets listed, then go to VMAppExtension:

Screenshot showing virtual machine scale sets application status.

Delete the VM Application

To delete the VM Application resource, you need to first delete all its versions. Deleting the application version causes deletion of the application version resource from Azure Compute Gallery and all its replicas. The application blob in Storage Account used to create the application version is unaffected. After deleting the application version, if any VM is using that version, then reimage operation on those VMs will fail. Use 'latest' keyword as the version number in the 'applicationProfile' instead of hard coding the version number to address this failure.
However if the application is deleted, then VM fails during reimage operation since there are no versions available for Azure to install. The VM profile needs to be updated to not use the VM Application.

Delete the VM Application version:

Remove-AzGalleryApplicationVersion -ResourceGroupName $rgNmae -GalleryName $galleryName -GalleryApplicationName $galleryApplicationName -Name $name

Delete the VM Application after all its versions are deleted:

Remove-AzGalleryApplication -ResourceGroupName $rgNmae -GalleryName $galleryName -Name $name