Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

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 and nested virtualization that is supported by certain Azure instance types to accomplish this.

Prerequisites#

  1. Install Pulumi
  2. Configure Azure credentials
  3. Install Python
  4. Install libvirt. The libvirt provider uses the libvirt module, so libvirt must be installed on the machine from which you run Pulumi.

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Log in to the Azure CLI (you will be prompted to do this during deployment if you forget this step):

    Terminal window
    az login
  3. Install dependencies:

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

    Terminal window
    pulumi config set azure-native:location westus
  5. Run pulumi up to preview and deploy changes:

    Terminal window
    pulumi up
    Previewing changes:
    ...
    Performing changes:
    ...
    Resources:
    + 12 created
    Duration: 3m36s
  6. 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 looks 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.

Cleaning up#

Once you’re finished experimenting, destroy your stack and remove it to avoid incurring any additional cost:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.