Migrating Virtual Machines to Red Hat OpenShift Virtualization with Ansible Automation Platform/Ch 1. Introduction to VM Migration and OpenShift Virtualization

Chapter 1

Introduction to VM Migration and OpenShift Virtualization

0:00
1x

Chapter Summary

# Chapter 1: Introduction to VM Migration and OpenShift Virtualization The virtualization landscape is currently undergoing its most significant transformation in over a decade. As organizations look to consolidate their infrastructure and bridge the gap between legacy monolithic applications and m...

Chapter 1: Introduction to VM Migration and OpenShift Virtualization

The virtualization landscape is currently undergoing its most significant transformation in over a decade. As organizations look to consolidate their infrastructure and bridge the gap between legacy monolithic applications and modern microservices, the "siloed" approach to managing Virtual Machines (VMs) and Containers is becoming a liability.

In this chapter, we will explore the technical foundations of Red Hat OpenShift Virtualization, the architectural shift it represents, and why the Ansible Automation Platform (AAP) is the essential glue for executing high-scale, enterprise-grade migrations.

The Convergence of VMs and Containers

For years, IT departments maintained two distinct stacks: one for virtualized workloads (typically VMware or oVirt) and one for containerized workloads (Kubernetes/OpenShift). OpenShift Virtualization, based on the open-source KubeVirt project, eliminates this duality by allowing VMs to run natively within a Kubernetes cluster.

Why OpenShift Virtualization?

OpenShift Virtualization isn't just a "me-too" hypervisor. It treats a VM as a first-class citizen within the Kubernetes ecosystem. This means:

  • Unified Networking: VMs and Pods share the same Software Defined Network (SDN).
  • Unified Storage: VMs use the same Container Storage Interface (CSI) drivers as your containers.
  • Unified Operations: Your monitoring (Prometheus), logging (Elasticsearch), and CI/CD pipelines work identically for both.

"The goal of OpenShift Virtualization is not to simply replace your hypervisor, but to modernize the way you manage virtual resources by applying DevOps and GitOps principles to legacy workloads."

Understanding the Architecture

To migrate effectively, an advanced practitioner must understand what happens under the hood. When you run a VM on OpenShift, it is encapsulated within a Linux container (Pod).

  1. The Virt-Launcher Pod: Every running VM corresponds to a Pod. The
    text
    virt-launcher
    process inside the pod handles the QEMU/KVM instance.
  2. Custom Resource Definitions (CRDs): OpenShift Virtualization introduces new objects like
    text
    VirtualMachine
    (the definition of the VM) and
    text
    VirtualMachineInstance
    (the running instance).
  3. CDI (Containerized Data Importer): This is the engine that handles data movement. It pulls disks from external sources (S3, HTTP, or VMware) and converts them into OpenShift-native
    text
    DataVolumes
    .

Real-World Example: The "Pet" VM vs. The "Cattle" VM

In a traditional environment, a database server is a "Pet"—manually configured and carefully maintained. By migrating it to OpenShift Virtualization, you can wrap that "Pet" in a "Cattle" framework. You can use Kubernetes

text
Service
objects to provide a stable IP for the VM, even if the underlying Pod is rescheduled to a different physical node.

The Role of Ansible Automation Platform (AAP)

If OpenShift Virtualization is the destination, Ansible is the vehicle. While the Migration Toolkit for Virtualization (MTV) provides a GUI for migrations, advanced users quickly find that GUI-driven migrations don't scale to thousands of VMs across multiple business units.

Ansible provides:

  • Pre-migration Validation: Checking if the source VM has compatible disk formats or specialized hardware pass-through that might break on OpenShift.
  • Orchestration: Shutting down the source VM, triggering the migration, and updating DNS/Load Balancers simultaneously.
  • Post-migration Configuration: Running
    text
    cloud-init
    or specific playbooks to reconfigure networking and internal services once the VM lands in its new home.

Code Example: Defining a VM in OpenShift via Ansible

Using the

text
kubernetes.core.k8s
module, we can define our target VM state in a declarative way.

yaml
- name: Create a Virtual Machine in OpenShift
  kubernetes.core.k8s:
    state: present
    definition:
      apiVersion: kubevirt.io/v1
      kind: VirtualMachine
      metadata:
        name: legacy-db-server
        namespace: production-vms
      spec:
        running: true
        template:
          spec:
            domain:
              cpu:
                cores: 4
              resources:
                requests:
                  memory: 8Gi
              devices:
                disks:
                  - name: rootdisk
                    disk:
                      bus: virtio
            volumes:
              - name: rootdisk
                dataVolume:
                  name: legacy-db-root-dv

Migration Strategies: Rehost vs. Replatform

As an advanced architect, you must decide which migration "path" each workload takes.

1. Rehosting (Lift and Shift)

This is the most common use case for OpenShift Virtualization. You move the VM bit-for-bit.

  • Pros: Low risk, fast.
  • Cons: You carry the "technical debt" of the old OS into the new environment.
  • Ansible's Role: Automated discovery of vCenter inventories and mapping them to OpenShift Namespaces.

2. Replatforming

Here, you might use Ansible to spin up a new VM on OpenShift using a standardized RHEL template and then use Ansible to migrate the data or application configuration from the old VM to the new one.

  • Pros: Clean OS, updated security patches, optimized for KubeVirt.
  • Cons: Higher effort per VM.

Practical Tips and Best Practices

Networking: The Multus Factor

Standard Kubernetes pods usually have one interface. However, legacy VMs often require multiple NICs for management, backup, and storage traffic.

  • Tip: Familiarize yourself with Multus CNI. It allows you to attach multiple network interfaces to a VM Pod, enabling bridge networking that keeps your VMs on their original VLANs.

Storage: Think "Thin"

When migrating, ensure your

text
StorageClass
on OpenShift supports dynamic provisioning and, ideally, thin provisioning.

  • Practice: Use DataVolumes rather than raw PersistentVolumeClaims (PVCs). DataVolumes are "smart" and can handle the orchestration of the CDI to import your image automatically.

The "Migration Hook"

Ansible is excellent for "hooks." A migration hook is a script or playbook that runs at a specific stage (e.g., Pre-migration to stop a database service, or Post-migration to update an IP in a CMDB like NetBox).

yaml
# Example: Post-migration hook to update CMDB
- name: Update NetBox with new VM location
  netbox.netbox.netbox_virtual_machine:
    netbox_url: "{{ netbox_url }}"
    netbox_token: "{{ netbox_token }}"
    data:
      name: "{{ vm_name }}"
      cluster: "OpenShift-Prod-01"
      status: "active"
    state: present

Preparing for the Journey

In the upcoming chapters, we will dive deep into the technical implementation. We will build an automated pipeline that:

  1. Discovers VMs in a VMware vSphere environment.
  2. Assesses them for compatibility using Ansible-driven logic.
  3. Executes the migration using the Migration Toolkit for Virtualization (MTV) API.
  4. Verifies the health of the VM on OpenShift.

Migration is not just about moving data; it’s about moving trust. By the end of this book, you will have the tools to move mission-critical workloads with the confidence that only automation can provide.

Summary Checklist for Chapter 1

  • [ ] Understand that OpenShift Virtualization is KubeVirt-based.
  • [ ] Recognize that a VM on OpenShift is a Pod, benefitting from Kubernetes scheduling.
  • [ ] Identify Ansible as the primary tool for orchestrating the migration lifecycle.
  • [ ] Differentiate between the
    text
    VirtualMachine
    and
    text
    VirtualMachineInstance
    objects.
  • [ ] Prepare for "Network thinking"—moving from single-interface pods to multi-interface (Multus) VMs.

In Chapter 2, we will set up our laboratory environment, including the installation of the OpenShift Virtualization Operator and the configuration of the Migration Toolkit for Virtualization.

What You Learned

  • 1

    OpenShift Virtualization integrates VMs into Kubernetes for streamlined management, eliminating the need for separate stacks.

  • 2

    It offers unified networking and storage for both VMs and containers, enhancing operational efficiency.

  • 3

    The Ansible Automation Platform is critical for executing scalable, enterprise-grade migrations within this new architecture.

📖 Key Terms

OpenShift Virtualization

A feature of Red Hat OpenShift that allows users to manage both containerized applications and virtual machines in a unified platform.

Ansible Automation Platform

A comprehensive suite of tools for automating cloud provisioning, configuration management, application deployment, and many other IT tasks.

VM Migration

The process of moving virtual machines from one physical host to another or from one virtualization environment to another with minimal downtime.

Container orchestration

Automating the deployment, scaling, and management of containerized applications, typically using tools like Kubernetes.

High Availability (HA)

A design approach that ensures a certain level of operational performance, usually uptime, by redundancy and failover mechanisms in the event of a failure.

Quiz requires login

Sign in to take the quiz and track your progress.