Coder Social home page Coder Social logo

isabella232 / nested-virtualization-image-builder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/nested-virtualization-image-builder

0.0 0.0 0.0 318 KB

License: MIT License

Dockerfile 3.58% PowerShell 25.60% Bicep 50.69% HCL 9.24% Shell 10.89%

nested-virtualization-image-builder's Introduction

nested-virtualization-image-builder

Virtual machine images are typically customized from base images already present in the Azure Marketplace or an organization's Azure Compute Gallery. Other times, you may need to build and upload images from scratch. This repository shows how to combine nested virtualization with Packer to bootstrap these images in a repeatable and cost-effective manner.

Logical architecture

Prerequisites

  • An Azure subscription where you hold the Owner role
  • Azure CLI

Usage

The first step is to deploy the builder VM and the supporting resources needed to capture images. It will take about 10 minutes to provision resources and configure the builder.

# Login to Azure
az login

# Choose an Azure region for your builder
LOCATION=westus3

# Deploy the builder VM and supporting resources
az deployment sub create -l $LOCATION -f ./builder/bicep/main.bicep -p "location=${LOCATION}"

Navigate to the VM in the Azure Portal. In the top bar, click Connect -> RDP, download the RDP file, then connect to the builder VM. Your credentials are:

  • Username: azureuser
  • Password: <the password you entered during deployment>

The builder VM is already configured with the tools needed to build images. Inside the builder VM, open PowerShell as Administrator and run the following commands to build an image from one of the samples provided in the repo.

# Clone the repo
# core.autocrlf=input will ensure that LF doesn't get converted to CRLF, which breaks scripts when building Linux images
git clone https://github.com/Azure-Samples/nested-virtualization-image-builder --config core.autocrlf=input

# Build a sample Ubuntu 20.04 image
cd .\nested-virtualization-image-builder\images\ubuntu2004\
packer build .\ubuntu2004.pkr.hcl

After your image is built, you will have a .vhd file that contains a generalized OS image. The next step is to upload it as a Page Blob to an Azure Storage Account, then register it as a Managed Image in your subscription. In PowerShell on the builder:

# Use Managed Identity for azcopy
azcopy login --identity

# Use Managed Identity for azure-cli
az login --identity

# Upload the VHD to blob storage
$storageAccount = az deployment group show -g builder -n storage --query 'properties.outputs.storageAccount.value' -o tsv
azcopy copy '.\output-ubuntu2004\Virtual Hard Disks\packer-ubuntu2004.vhd' "https://$storageAccount.blob.core.windows.net/images/ubuntu2004.vhd"

# Register the image
az image create -g builder -n ubuntu2004 --os-type Linux --source "https://$storageAccount.blob.core.windows.net/images/ubuntu2004.vhd"

Cleanup

To clean up all Azure resources deployed by this sample, you can delete the parent Resource Group

az group delete -n builder

Resources

VM sizes that support nested virtualization

Most general purpose, compute-optimized, and memory-optimized VM sizes from Dv3/Dsv3 and newer have nested virtualization enabled. The docs for each VM size will have the details.

For example, Dv3 and Dsv3-series reads "Nested Virtualization: Supported".

nested-virtualization-image-builder's People

Contributors

joshuaphelpsms avatar kjeffc avatar microsoftopensource avatar noelbundick-msft avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.