KVM Virtualization Cookbook

Book description

Deploy, manage, and scale virtual instances using Kernel-based Virtual Machines

About This Book

  • Build, manage and scale virtual machines with practical step-by-step examples
  • Leverage the libvirt user-space tools and libraries to manage the life-cycle of KVM instances
  • Deploy and scale applications inside KVM virtual machines with OpenStack

Who This Book Is For

If you are a system administrator working KVM virtualization, this book will help you grow on your expertise of working with the infrastructure to manage things in a better way. You should have a knowledge of working with Linux based systems.

What You Will Learn

  • Deploy different workloads in isolation with KVM virtualization and better utilize the available compute resources
  • Explore the benefits of running applications with KVM and learn to prevent the “bad-neighbor” effect
  • Leveraging various networking technologies in the context of virtualization with Open vSwitch and the Linux bridge.
  • Create KVM instances using Python and inspect running KVM instances
  • Understand Kernel Tuning for enhanced KVM performance and better memory utilization

In Detail

Virtualization technologies such as KVM allow for better control over the available server resources, by deploying multiple virtual instances on the same physical host, or clusters of compute resources. With KVM it is possible to run various workloads in isolation with the hypervisor layer providing better tenant isolation and higher degree of security.

This book will provide a deep dive into deploying KVM virtual machines using qemu and libvirt and will demonstrate practical examples on how to run, scale, monitor, migrate and backup such instances. You will also discover real production ready recipes on deploying KVM instances with OpenStack and how to programatically manage the life cycle of KVM virtual machines using Python. You will learn numerous tips and techniques which will help you deploy & plan the KVM infrastructure. Next, you will be introduced to the working of libvirt libraries and the iPython development environment.

Finally, you will be able to tune your Linux kernel for high throughput and better performance. By the end of this book, you will gain all the knowledge needed to be an expert in working with the KVM virtualization infrastructure.

Style and approach

This book takes a complete practical approach with many step-by-step example recipes on how to use KVM in production. The book assumes certain level of expertise with Linux systems and virtualization in general. Some knowledge of Python programming is encouraged, to fully take advantage of the code recipes.

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Conventions
    6. Reader feedback
    7. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. Getting Started with QEMU and KVM
    1. Introduction
    2. Installing and configuring QEMU
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Managing disk images with qemu-img
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Preparing images for OS installation with qemu-nbd
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Installing a custom OS on the image with debootstrap
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Resizing an image
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using pre-existing images
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Running virtual machines with qemu-system-*
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Starting the QEMU VM with KVM support
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Connecting to a running instance with VNC
      1. Getting ready
      2. How to do it...
      3. How it works...
  3. Using libvirt to Manage KVM
    1. Introduction
    2. Installing and configuring libvirt
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Defining KVM instances
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Starting, stopping, and removing KVM instances
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Inspecting and editing KVM configs
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Building new KVM instances with virt-install and using the console
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Managing CPU and memory resources in KVM
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Attaching block devices to virtual machines
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Sharing directories between a running VM and the host OS
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Autostarting KVM instances
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Working with storage pools
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    12. Managing volumes
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Managing secrets
      1. Getting ready
      2. How to do it...
      3. How it works...
  4. KVM Networking with libvirt
    1. Introduction
    2. The Linux bridge
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. The Open vSwitch
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Configuring NAT forwarding network
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Configuring bridged network
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Configuring PCI passthrough network
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Manipulating network interfaces
      1. Getting ready
      2. How to do it...
      3. How it works...
  5. Migrating KVM Instances
    1. Introduction
    2. Manual offline migration using an iSCSI storage pool
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Manual offline migration using GlusterFS shared volumes
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Online migration using the virsh command with shared storage
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Offline migration using the virsh command and local image
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Online migration using the virsh command and local image
      1. Getting ready
      2. How to do it...
      3. How it works...
  6. Monitoring and Backup of KVM Virtual Machines
    1. Introduction
    2. Resource usage collection with libvirt
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Monitoring KVM instances with Sensu
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Simple KVM backups with tar and rsync
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating snapshots
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Listing snapshots
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Inspecting snapshots
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Editing snapshots
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Reverting snapshots
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Deleting snapshots
      1. Getting ready
      2. How to do it...
      3. How it works...
  7. Deploying KVM Instances with OpenStack
    1. Introduction
    2. Preparing the host for the OpenStack deployment
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Installing and configuring the OpenStack Keystone identity service
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Installing and configuring the OpenStack Glance image service
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Installing and configuring the OpenStack Nova compute service
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Installing and configuring the OpenStack Neutron networking service
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Building and inspecting KVM instances with OpenStack
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Stopping KVM instances with OpenStack
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Terminating KVM instances with OpenStack
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. Using Python to Build and Manage KVM Instances
    1. Introduction
    2. Installing and using the Python libvirt library
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Defining KVM instances with Python
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Starting, stopping, and deleting KVM instances with Python
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Inspecting KVM instances with Python
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Building a simple REST API server with libvirt and bottle
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  9. Kernel Tuning for KVM Performance
    1. Introduction
    2. Tuning the kernel for low I/O latency
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Memory tuning for KVM guests
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. CPU performance options
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. NUMA tuning with libvirt
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There is more...
    6. Tuning the kernel for network performance
      1. Getting ready
      2. How to do it...
      3. How it works...

Product information

  • Title: KVM Virtualization Cookbook
  • Author(s): Konstantin Ivanov
  • Release date: June 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781788294676