0%

Learn how to configure, automate, orchestrate, troubleshoot, and monitor KVM-based environments capable of scaling to private and hybrid cloud models

Key Features

  • Gain expert insights into Linux virtualization and the KVM ecosystem with this comprehensive guide
  • Learn to use various Linux tools such as QEMU, oVirt, libvirt, Cloud-Init, and Cloudbase-Init
  • Scale, monitor, and troubleshoot your VMs on various platforms, including OpenStack and AWS

Book Description

Kernel-based Virtual Machine (KVM) enables you to virtualize your data center by transforming your Linux operating system into a powerful hypervisor that allows you to manage multiple operating systems with minimal fuss. With this book, you'll gain insights into configuring, troubleshooting, and fixing bugs in KVM virtualization and related software.

This second edition of Mastering KVM Virtualization is updated to cover the latest developments in the core KVM components - libvirt and QEMU. Starting with the basics of Linux virtualization, you'll explore VM lifecycle management and migration techniques. You'll then learn how to use SPICE and VNC protocols while creating VMs and discover best practices for using snapshots. As you progress, you'll integrate third-party tools with Ansible for automation and orchestration. You'll also learn to scale out and monitor your environments, and will cover oVirt, OpenStack, Eucalyptus, AWS, and ELK stack. Throughout the book, you'll find out more about tools such as Cloud-Init and Cloudbase-Init. Finally, you'll be taken through the performance tuning and troubleshooting guidelines for KVM-based virtual machines and a hypervisor.

By the end of this book, you'll be well-versed with KVM virtualization and the tools and technologies needed to build and manage diverse virtualization environments.

What you will learn

  • Implement KVM virtualization using libvirt and oVirt
  • Delve into KVM storage and network
  • Understand snapshots, templates, and live migration features
  • Get to grips with managing, scaling, and optimizing the KVM ecosystem
  • Discover how to tune and optimize KVM virtualization hosts
  • Adopt best practices for KVM platform troubleshooting

Who this book is for

If you are a systems administrator, DevOps practitioner, or developer with Linux experience looking to sharpen your open-source virtualization skills, this virtualization book is for you. Prior understanding of the Linux command line and virtualization is required before getting started with this book.

Table of Contents

  1. Mastering KVM Virtualization Second Edition
  2. Why subscribe?
  3. Contributors
  4. About the authors
  5. About the reviewer
  6. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Code in Action
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  8. Section 1: KVM Virtualization Basics
  9. Chapter 1: Understanding Linux Virtualization
    1. Linux virtualization and how it all started
    2. Types of virtualization
    3. Using the hypervisor/virtual machine manager
    4. Type 1 and type 2 hypervisors
    5. Open source virtualization projects
    6. Xen
    7. KVM
    8. What Linux virtualization offers you in the cloud
    9. Summary
    10. Questions
    11. Further reading
  10. Chapter 2: KVM as a Virtualization Solution
    1. Virtualization as a concept
    2. Virtualized versus physical environments
    3. Why is virtualization so important?
    4. Hardware requirements for virtualization
    5. Software requirements for virtualization
    6. The internal workings of libvirt, QEMU, and KVM
    7. libvirt
    8. QEMU
    9. QEMU – KVM internals
    10. Data structures
    11. Threading models in QEMU
    12. KVM
    13. Data structures
    14. Execution flow of vCPU
    15. Summary
    16. Questions
    17. Further reading
  11. Section 2: libvirt and ovirt for Virtual Machine Management
  12. Chapter 3: Installing KVM Hypervisor, libvirt, and oVirt
    1. Getting acquainted with QEMU and libvirt
    2. Getting acquainted with oVirt
    3. Installing QEMU, libvirt, and oVirt
    4. Installing the first virtual machine in KVM
    5. Automating virtual machine installation
    6. Installing oVirt
    7. Starting a virtual machine using QEMU and libvirt
    8. Summary
    9. Questions
    10. Further reading
  13. Chapter 4: Libvirt Networking
    1. Understanding physical and virtual networking
    2. Virtual networking
    3. Libvirt NAT network
    4. Libvirt routed network
    5. Libvirt isolated network
    6. Using userspace networking with TAP and TUN devices
    7. Implementing Linux bridging
    8. Configuring Open vSwitch
    9. Other Open vSwitch use cases
    10. Understanding and using SR-IOV
    11. Understanding macvtap
    12. Summary
    13. Questions
    14. Further reading
  14. Chapter 5: Libvirt Storage
    1. Introduction to storage
    2. Storage pools
    3. Local storage pools
    4. Libvirt storage pools
    5. NFS storage pool
    6. iSCSI and SAN storage
    7. Storage redundancy and multipathing
    8. Gluster and Ceph as a storage backend for KVM
    9. Gluster
    10. Ceph
    11. Virtual disk images and formats and basic KVM storage operations
    12. Getting image information
    13. Attaching a disk using virt-manager
    14. Attaching a disk using virsh
    15. Creating an ISO image library
    16. Deleting a storage pool
    17. Creating storage volumes
    18. Creating volumes using the virsh command
    19. Deleting a volume using the virsh command
    20. The latest developments in storage – NVMe and NVMeOF
    21. Summary
    22. Questions
    23. Further reading
  15. Chapter 6: Virtual Display Devices and Protocols
    1. Using virtual machine display devices
    2. Physical and virtual graphics cards in VDI scenarios
    3. GPU PCI passthrough
    4. Discussing remote display protocols
    5. Remote display protocols history
    6. Types of remote display protocols
    7. Using the VNC display protocol
    8. Why VNC?
    9. Using the SPICE display protocol
    10. Adding a SPICE graphics server
    11. Methods to access a virtual machine console
    12. Getting display portability with noVNC
    13. Summary
    14. Questions
    15. Further reading
  16. Chapter 7: Virtual Machines: Installation, Configuration, and Life Cycle Management
    1. Creating a new VM using virt-manager
    2. Using virt-manager
    3. Using virt-* commands
    4. Creating a new VM using Cockpit
    5. Creating a new VM using oVirt
    6. Configuring your VM
    7. Adding and removing virtual hardware from your VM
    8. Migrating VMs
    9. Benefits of VM migration
    10. Setting up the environment
    11. Offline migration
    12. Live or online migration
    13. Summary
    14. Questions
    15. Further reading
  17. Chapter 8: Creating and Modifying VM Disks, Templates, and Snapshots
    1. Modifying VM images using libguestfs tools
    2. virt-v2v
    3. virt-p2v
    4. guestfish
    5. VM templating
    6. Working with templates
    7. Deploying VMs from a template
    8. virt-builder and virt-builder repos
    9. virt-builder repositories
    10. Snapshots
    11. Working with internal snapshots
    12. Managing snapshots using virt-manager
    13. Working with external disk snapshots
    14. Use cases and best practices while using snapshots
    15. Summary
    16. Questions
    17. Further reading
  18. Section 3: Automation, Customization, and Orchestration for KVM VMs
  19. Chapter 9: Customizing a Virtual Machine with cloud-init
    1. What is the need for virtual machine customization?
    2. Understanding cloud-init
    3. Understanding cloud-init architecture
    4. Installing and configuring cloud-init at boot time
    5. Cloud-init images
    6. Cloud-init data sources
    7. Passing metadata and user data to cloud-init
    8. Using cloud-init modules
    9. Examples on how to use a cloud-config script with cloud-init
    10. The first deployment
    11. The second deployment
    12. The third deployment
    13. Summary
    14. Questions
    15. Further reading
  20. Chapter 10: Automated Windows Guest Deployment and Customization
    1. The prerequisites to creating Windows VMs on KVM
    2. Creating Windows VMs using the virt-install utility
    3. Customizing Windows VMs using cloudbase-init
    4. cloudbase-init customization examples
    5. Troubleshooting common cloudbase-init customization issues
    6. Summary
    7. Questions
    8. Further reading
  21. Chapter 11: Ansible and Scripting for Orchestration and Automation
    1. Understanding Ansible
    2. Automation approaches
    3. Introduction to Ansible
    4. Deploying and using AWX
    5. Deploying Ansible
    6. Provisioning a virtual machine using the kvm_libvirt module
    7. Working with playbooks
    8. Installing KVM
    9. Using Ansible and cloud-init for automation and orchestration
    10. Orchestrating multi-tier application deployment on KVM VM
    11. Learning by example – various examples of using Ansible with KVM
    12. Summary
    13. Questions
    14. Further reading
  22. Section 4: Scalability, Monitoring, Performance Tuning, and Troubleshooting
  23. Chapter 12: Scaling Out KVM with OpenStack
    1. Introduction to OpenStack
    2. Software-defined networking
    3. Understanding VXLAN
    4. Understanding GENEVE
    5. OpenStack components
    6. Swift
    7. Nova
    8. Glance
    9. Horizon
    10. Designate
    11. Keystone
    12. Neutron
    13. Additional OpenStack use cases
    14. Creating a Packstack demo environment for OpenStack
    15. Provisioning the OpenStack environment
    16. Installing OpenStack step by step
    17. OpenStack administration
    18. Day-to-day administration
    19. Identity management
    20. Integrating OpenStack with Ansible
    21. Installing an Ansible deployment server
    22. Configuring the Ansible inventory
    23. Running Ansible playbooks
    24. Summary
    25. Questions
    26. Further reading
  24. Chapter 13: Scaling out KVM with AWS
    1. Introduction to AWS
    2. Approaching the cloud
    3. Multi-cloud
    4. Shadow IT
    5. Market share
    6. Big infrastructure but no services
    7. Pricing
    8. Data centers
    9. Placement is the key
    10. AWS services
    11. Preparing and converting virtual machines for AWS
    12. What do we want to do?
    13. Uploading an image to EC2
    14. Building hybrid KVM clouds with Eucalyptus
    15. How do you install it?
    16. Using Eucalyptus for AWS control
    17. Summary
    18. Questions
    19. Further reading
  25. Chapter 14: Monitoring the KVM Virtualization Platform
    1. Monitoring the KVM virtualization platform
    2. Introduction to the open source ELK solution
    3. Elasticsearch
    4. Logstash
    5. Kibana
    6. Setting up and integrating the ELK stack
    7. Workflow
    8. Configuring data collector and aggregator
    9. Creating charts in Kibana
    10. Creating custom utilization reports
    11. ELK and KVM
    12. Summary
    13. Questions
    14. Further reading
  26. Chapter 15: Performance Tuning and Optimization for KVM VMs
    1. It's all about design
    2. General hardware design
    3. VM design
    4. Tuning the VM CPU and memory performance
    5. CPU pinning
    6. Working with memory
    7. Getting acquainted with KSM
    8. Tuning the CPU and memory with NUMA
    9. NUMA memory allocation policies
    10. Understanding emulatorpin
    11. KSM and NUMA
    12. Automatic NUMA balancing
    13. The numactl command
    14. Understanding numad and numastat
    15. Virtio device tuning
    16. Block I/O tuning
    17. Network I/O tuning
    18. How to turn it on
    19. KVM guest time-keeping best practices
    20. Software-based design
    21. Summary
    22. Questions
    23. Further reading
  27. Chapter 16: Troubleshooting Guidelines for the KVM Platform
    1. Verifying the KVM service status
    2. KVM services logging
    3. Enabling debug mode logging
    4. Advanced troubleshooting tools
    5. oVirt
    6. oVirt and KVM storage problems
    7. Problems with snapshots and templates – virtual machine customization
    8. Problems working with Ansible and OpenStack
    9. Dependencies
    10. Troubleshooting Eucalyptus
    11. AWS and its verbosity, which doesn't help
    12. Paying attention to details
    13. Troubleshooting problems with the ELK stack
    14. Best practices for troubleshooting KVM issues
    15. Summary
    16. Questions
    17. Further reading
  28. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
3.137.213.128