Azure Compute Gallery
Complete the full lesson to earn 25 points
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks and see fewer ads — read each lesson on a single page with Pro
Azure Compute Gallery: Mastering Image Management for Azure Virtual Desktop
Introduction: The Backbone of Scalable Infrastructure
In the world of Azure Virtual Desktop (AVD), the session host is the engine that drives the user experience. Whether you are managing a small pool of ten users or a global deployment for thousands, the consistency and reliability of your desktop environment depend entirely on the image you deploy. This is where the Azure Compute Gallery (formerly known as Shared Image Gallery) becomes essential. It is not just a storage location for virtual machine snapshots; it is a sophisticated lifecycle management tool designed to simplify the sharing, versioning, and global distribution of your custom images.
Without a structured approach to image management, administrators often find themselves manually updating individual virtual machines, leading to "configuration drift," where no two machines are exactly alike. This inconsistency creates a nightmare for troubleshooting and security patching. The Azure Compute Gallery solves this by providing a centralized repository where you can define an image once, version it as your software stack evolves, and replicate it across multiple Azure regions. Understanding how to build, version, and distribute images using this service is a fundamental skill for any cloud engineer or system administrator working with AVD.
Understanding the Architecture of Azure Compute Gallery
To effectively use the Azure Compute Gallery, you must first understand the hierarchy of the resources involved. The gallery acts as a container for your image definitions, which in turn hold the specific versions of your virtual machine images. This logical separation allows for a clean, organized workflow that scales as your organization grows.
The Hierarchical Structure
- Azure Compute Gallery: This is the top-level resource. It acts as the organizational boundary and the primary point for managing access control. You can think of it as the "library" where all your image collections reside.
- Image Definition: Inside the gallery, you create image definitions. These represent a logical grouping of images, such as "Windows 11 Enterprise AVD" or "Windows 10 with Office 365." The definition dictates the operating system type, the state (generalized or specialized), and the recommended hardware requirements.
- Image Version: This is the actual artifact. Each time you update your software, install new patches, or change configurations, you create a new version of the image definition. Versions are typically defined using a major.minor.patch format (e.g., 1.0.1), allowing you to roll back to a previous state if an update introduces bugs.
Callout: Generalized vs. Specialized Images When creating image definitions, you must choose between generalized and specialized. A generalized image has had machine-specific information (like the computer name or SID) removed using Sysprep. This is the standard for AVD host pools because it allows Azure to generate a unique identity for every new VM created. A specialized image is a direct copy of an existing VM, including all its unique settings, which is faster to deploy but requires more careful management of identity and computer names.
Benefits of Using the Azure Compute Gallery
The primary reason to use the Azure Compute Gallery over basic managed image snapshots is the ability to manage the entire lifecycle of your virtual machine images. By moving away from manual snapshots, you gain several operational advantages that directly impact the stability of your AVD environment.
Key Operational Advantages
- Replication Automation: You can define a target region and an image replica count, and Azure will automatically copy your image to those locations. This is vital for AVD deployments that span multiple geographical regions, ensuring that your session hosts have low-latency access to the image source.
- Versioning and Rollbacks: If you deploy a new image version that causes application crashes, you don't need to panic. Because the gallery keeps older versions, you can simply point your AVD host pool scaling plans back to the previous, known-good version of the image.
- RBAC Integration: Because the gallery is a native Azure resource, you can use Role-Based Access Control (RBAC) to manage who can create, read, or delete images. This allows you to set up a workflow where a build pipeline has write access, but your desktop support team only has read access.
- Shared Access: You can share a gallery across different subscriptions or even across different Azure tenants. This is particularly useful for managed service providers (MSPs) who need to provide a standardized image to multiple customer tenants.
Step-by-Step Implementation: Creating Your First Gallery
Setting up an Azure Compute Gallery is a straightforward process, but it requires careful planning regarding naming conventions and regional placement. Follow these steps to establish your image management foundation.
Step 1: Creating the Gallery Resource
You can create a gallery via the Azure Portal, PowerShell, or the Azure CLI. For automation purposes, the Azure CLI is often preferred.
# Create a resource group for your image gallery
az group create --name ImageGalleryRG --location eastus
# Create the gallery
az sig create --resource-group ImageGalleryRG --gallery-name MyAVDGallery --location eastus
Step 2: Defining the Image
Once the gallery exists, you need to define the image type. This is where you specify the operating system and the intended use case.
# Create an image definition
az sig image-definition create \
--resource-group ImageGalleryRG \
--gallery-name MyAVDGallery \
--gallery-image-definition MyAVDImageDef \
--publisher MyCompany \
--offer Windows11 \
--sku Enterprise \
--os-type Windows \
--os-state generalized
Step 3: Creating and Versioning the Image
To create a version, you typically start with a "Gold Image" virtual machine. You install all your applications, run Windows updates, and perform any necessary registry tweaks. Once the VM is ready, you capture it as an image version.
Warning: The Importance of Sysprep Before capturing a Windows virtual machine as a generalized image, you must run the System Preparation tool (Sysprep). If you skip this step, every VM you deploy from that image will share the same security identifier (SID) and computer name, which will cause catastrophic failures in your AVD environment and domain join processes.
Automating Image Builds with Azure Image Builder
While you can manually create images, the industry standard for AVD is to use Azure Image Builder (AIB). AIB is essentially a managed service that runs HashiCorp Packer behind the scenes, allowing you to define your image creation process in a JSON template.
Why Automate Your Image Pipeline?
Manual image creation is prone to human error. A technician might forget to install a specific security patch or leave a temporary file on the desktop. Automation ensures that every image is built exactly the same way, every time.
A Simple Image Builder Template
An Image Builder template consists of three main components:
- Source: Where the base image comes from (e.g., the Azure Marketplace).
- Customize: A list of scripts or commands to run (e.g., installing Chrome, Teams, or FSLogix).
- Distribute: Where the final image goes (your Azure Compute Gallery).
{
"type": "Microsoft.VirtualMachineImages/imageTemplates",
"name": "AVDTemplate",
"properties": {
"buildTimeoutInMinutes": 60,
"source": {
"type": "PlatformImage",
"publisher": "MicrosoftWindowsDesktop",
"offer": "Windows-11",
"sku": "win11-22h2-avd",
"version": "latest"
},
"customize": [
{
"type": "PowerShell",
"name": "InstallApps",
"inline": [
"choco install googlechrome -y",
"choco install vcredist-all -y"
]
}
],
"distribute": [
{
"type": "SharedImage",
"galleryImageId": "/subscriptions/.../images/MyAVDImageDef"
}
]
}
}
This JSON structure is a powerful tool. By checking this file into a version control system like GitHub or Azure DevOps, you create a "Source of Truth" for your AVD infrastructure. If a new version of an application is released, you simply update the script in the customize block, trigger the build, and a new version is automatically pushed to your gallery.
Comparison: Traditional Snapshots vs. Compute Gallery
Many administrators start by using managed snapshots because they are easy to understand. However, as the complexity of an AVD environment increases, the limitations of snapshots become clear.
| Feature | Managed Snapshots | Azure Compute Gallery |
|---|---|---|
| Versioning | No built-in versioning | Native versioning (1.0.0, 1.0.1) |
| Sharing | Requires manual copying | Built-in cross-subscription/tenant sharing |
| Global Reach | Requires manual replication | Automatic regional replication |
| Lifecycle | None | Lifecycle management (decommissioning) |
| Automation | Limited | Native integration with Image Builder |
Callout: Why Snapshots Fail at Scale Snapshots are essentially "dumb" copies of a disk. They have no metadata, no relationship to other versions, and no mechanism for regional distribution. If you have 50 host pools across 5 regions, using snapshots means you are manually managing hundreds of individual disk objects, which is a recipe for operational failure.
Best Practices for Image Lifecycle Management
Managing images effectively is not just about the technology; it is about the process. Follow these industry-standard practices to keep your AVD environment healthy.
1. The "Golden Image" Methodology
Always maintain a single, clean source for your images. Never modify a session host directly in the production host pool. If you need to make a change, update your template, build a new image version, and redeploy the host pool. This ensures that your production environment remains pristine and predictable.
2. Regular Patching Cadence
Establish a monthly schedule for image updates. Since your images are versioned, you can build a new version (e.g., v1.1.0) on the second Tuesday of every month (Patch Tuesday). Once you have verified the image in a test host pool, you can update your production host pools to use the new version.
3. Use Tags for Organization
Azure tags are your best friend. Tag your image definitions and versions with metadata such as Environment: Production, OS: Windows 11, and BuildDate: 2023-10-01. This makes it significantly easier to audit your environment and understand which images are currently in use across your organization.
4. Implement Cleanup Policies
Over time, your gallery will accumulate many versions. While it is good to keep a few previous versions for rollback purposes, you do not need to keep every version you have ever created. Use Azure policies or automation scripts to delete image versions that are older than six months or that are no longer associated with any active host pools.
Common Pitfalls and How to Avoid Them
Even with the best tools, mistakes happen. Being aware of these common traps will save you significant time during the deployment phase.
- The "Domain Join" Loop: If you are using a specialized image, ensure that the computer name is properly handled during deployment. If you accidentally deploy multiple VMs with the same name, they will conflict in Active Directory, causing the domain join to fail repeatedly. Always prefer generalized images for AVD.
- Forgetting Prerequisites: When installing software in your image, ensure that you are installing the necessary prerequisites like the AVD Agent, the AVD Bootloader, and the FSLogix Apps service. If these are missing from your image, the VM will not be able to register with the AVD service, and users will never be able to connect.
- Ignoring Network Requirements: During the image build process, the build VM needs access to the public internet to download application installers and Windows updates. Ensure your Azure Image Builder has access to a subnet with outbound connectivity, or use a private link if your security policy restricts internet access.
- Over-complicating the Image: A common mistake is to try and put every application into the golden image. This leads to massive image sizes and long deployment times. Instead, use the golden image for the core OS and standard apps, and use technologies like MSIX App Attach or App Layering to deliver specialized applications dynamically.
Troubleshooting Image Distribution Issues
Sometimes, an image might fail to replicate to a specific region, or a host pool might fail to deploy using a new image version. When this happens, follow these diagnostic steps:
- Check the Replication Status: In the Azure Portal, navigate to your image version and check the "Replication" tab. If replication is stuck or failed, you can see the specific error messages for each region.
- Verify Permissions: Ensure that the service principal or managed identity used by your deployment pipeline has the
Readerrole on the image gallery and theContributorrole on the resource group where the host pool is being created. - Review the Build Logs: If you are using Azure Image Builder, the logs are stored in a resource group created by the service (usually named
IT_...). These logs contain detailed output from the build process, including any script failures. - Test Deployment: Before promoting a new image to production, always create a single test virtual machine from the new version in the target region. This allows you to verify that the image is bootable and that all applications are functioning correctly without impacting your users.
Note: When troubleshooting, keep in mind that the Azure Compute Gallery is a regional service. While you can replicate images across regions, the image definition itself lives in a specific home region. Always keep your gallery in the region where your administrative activities are most frequent to minimize latency.
Advanced Strategies: MSIX App Attach and Image Versioning
As your AVD environment matures, you may find that managing a single "master image" becomes too restrictive. This is where you should look into decoupling your applications from your base OS image.
Decoupling with MSIX App Attach
Instead of installing heavy applications like Adobe Creative Cloud or complex CAD software into your Windows image, you can package these applications as MSIX containers. These containers are stored on a file share (like Azure Files) and are attached to the user's session dynamically when they log in. This keeps your base image lightweight, reduces the time it takes to build new image versions, and allows you to update applications independently of the operating system.
Advanced Versioning Strategy
Consider a two-tier gallery strategy:
- Dev/Test Gallery: Where new image versions are built and verified by the IT team.
- Production Gallery: Where only "validated" images are replicated.
By using two separate galleries, you provide a safety barrier for your production environment. You can use an automated script or a CI/CD pipeline to copy an image version from the Dev gallery to the Production gallery only after it has passed a suite of automated integration tests.
Summary: Key Takeaways for Success
Mastering the Azure Compute Gallery is a journey of moving from manual, fragile configurations to automated, resilient infrastructure. By focusing on these principles, you will ensure that your AVD environment remains stable and scalable.
- Centralization is Key: Always use the Azure Compute Gallery as the single source of truth for your images. Avoid using individual snapshots, which are difficult to track and manage at scale.
- Automate Everything: Use Azure Image Builder to define your image build process as code. This eliminates configuration drift and ensures consistency across your entire fleet of session hosts.
- Embrace Versioning: Treat your images like software. Use semantic versioning (1.0.0) to track changes and always keep a known-good version available for quick rollbacks if a new deployment fails.
- Understand the Lifecycle: A well-managed gallery should be pruned regularly. Remove old, unused versions to save on storage costs and keep your administrative interface clean and manageable.
- Separate OS from Apps: As your environment grows, look for ways to move applications out of the base image using technologies like MSIX App Attach. This reduces the frequency of base image updates and speeds up your deployment pipeline.
- Security and Compliance: Use RBAC to restrict who can modify your images, and ensure that your build process includes security hardening steps such as disabling unnecessary services and enforcing group policies.
- Plan for Global Deployment: Take advantage of the automatic replication features of the gallery to ensure that your images are available in all regions where your AVD users are located, minimizing latency and deployment times.
By internalizing these concepts, you transition from being a reactive administrator who spends time fixing broken VMs to a proactive architect who builds robust, self-sustaining environments. The Azure Compute Gallery is not just a storage feature; it is the foundation of your AVD operational strategy. Treat it with the same rigor you would apply to your most critical production databases or networking infrastructure, and your users will benefit from a faster, more reliable desktop experience.
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles your daily points limit so you progress twice as fast, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× daily points limit
- ✓ Distraction-free lessons