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 (https://www.pulumi.com/registry/packages/libvirt/) and nested virtualization that is supported by certain Azure instance types to accomplish this.
Running the App#
-
The libvirt provider uses the libvirt module. Therefore, libvirt needs to be installed on the machine from which you are running pulumi.
- Mac:
brew install libvirt - Windows: See: https://libvirt.org/windows.html
- Others: https://libvirt.org/downloads.html
- Mac:
-
Create a new stack:
$ pulumi stack init dev -
Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):
$ az login -
Create a Python virtualenv, activate it, and install dependencies:
This installs the dependent packages needed for our Pulumi program.
Terminal window python3 -m venv venvsource venv/bin/activatepip3 install -r requirements.txt -
Set the Azure region location to use:
$ pulumi config set azure-native:location westus -
Run
pulumi upto preview and deploy changes:$ 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 will look something likeecho 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.