Using the Pulumi libvirt provider to deploy a VM on a KVM server
Uses libvirt to deploy a KVM VM on an Azure-hosted KVM server.
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set libvirt-py-vmcd pulumi-examples/libvirt-py-vmDeploys a KVM server in Azure and then deploys a small Linux VM on that KVM server. It uses the Pulumi libvirt provider and nested virtualization that is supported by certain Azure instance types to accomplish this.
Prerequisites#
- Install Pulumi
- Configure Azure credentials
- Install Python
- Install libvirt. The libvirt provider uses the libvirt module, so libvirt must be installed on the machine from which you run Pulumi.
- Mac:
brew install libvirt - Windows: See https://libvirt.org/windows.html
- Others: See https://libvirt.org/downloads.html
- Mac:
Deploying the example#
-
Create a new stack:
Terminal window pulumi stack init dev -
Log in to the Azure CLI (you will be prompted to do this during deployment if you forget this step):
Terminal window az login -
Install dependencies:
Terminal window python3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Set the Azure region location to use:
Terminal window pulumi config set azure-native:location westus -
Run
pulumi upto preview and deploy changes:Terminal window pulumi upPreviewing changes:...Performing changes:...Resources:+ 12 createdDuration: 3m36s -
Check the VM on the KVM host. The stack generates an output that provides a string you can execute to run
virshremotely on the KVM host. It looks something like:echo virsh list | ssh -i libvirt-ex-dev-kvm_server.priv kvmuser@1.2.3.4Additionally, you can ssh to the KVM host and use virsh locally to explore more details.
Cleaning up#
Once you’re finished experimenting, destroy your stack and remove it to avoid incurring any additional cost:
pulumi destroypulumi stack rm