Skip to main content

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:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set libvirt-py-vm
cd pulumi-examples/libvirt-py-vm

Deploys 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#

  1. The libvirt provider uses the libvirt module. Therefore, libvirt needs to be installed on the machine from which you are running pulumi.

  2. Create a new stack:

    $ pulumi stack init dev
  3. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):

    $ az login
  4. Create a Python virtualenv, activate it, and install dependencies:

    This installs the dependent packages needed for our Pulumi program.

    Terminal window
    python3 -m venv venv
    source venv/bin/activate
    pip3 install -r requirements.txt
  5. Set the Azure region location to use:

    $ pulumi config set azure-native:location westus
  6. Run pulumi up to preview and deploy changes:

    $ pulumi up
    Previewing changes:
    ...
    Performing changes:
    ...
    Resources:
    + 12 created
    Duration: 3m36s
  7. Check the VM on the KVM host: The stack generates an output that provides a string you can execute to run virsh remotely on the KVM host. It will look something like

    echo virsh list | ssh -i libvirt-ex-dev-kvm_server.priv kvmuser@1.2.3.4

    Additionally, you can ssh to the KVM host and use virsh locally to explore more details.

Related

The infrastructure as code platform for any cloud.