Skip to content
English - United States
  • There are no suggestions because the search field is empty.

Getting Started with Red Hat OpenShift Virtualization: A Guide for Operators

This guide provides a practical introduction to Red Hat OpenShift Virtualization, empowering operators to manage virtual machines (VMs) alongside containers on the same OpenShift platform. This unified approach simplifies operations and allows for a more agile infrastructure.

 

What is OpenShift Virtualization?

OpenShift Virtualization, based on the Kubevirt project, allows you to run and manage VMs on your OpenShift cluster, just like you manage containers. This eliminates the need for separate virtualization platforms and streamlines operations by providing a single pane of glass for managing all your workloads.

Prerequisites:

  • A running OpenShift cluster (version 4.x or later).
  • oc command-line tool configured to access your cluster.
  • Basic understanding of OpenShift concepts (Projects, Pods, Deployments, etc.).

Step 1: Enabling OpenShift Virtualization

OpenShift Virtualization is typically installed as an Operator. Check if it's already installed:


Bash



oc get csv -n openshift-cnv

If the kubevirt-operator CSV (Cluster Service Version) is not present, you'll need to install it. The easiest way is through the OperatorHub in the OpenShift web console.

  1. Navigate to the OperatorHub.
  2. Search for "OpenShift Virtualization."
  3. Click "Install." Choose the appropriate update channel and approval strategy.

Step 2: Exploring the OpenShift Virtualization Components

After installation, several Custom Resource Definitions (CRDs) are available for managing VMs. Key CRDs include:

  • VirtualMachine: Defines the VM itself, including its resources (CPU, memory, storage), operating system, and networking.
  • VirtualMachineInstance: Represents a running instance of a VirtualMachine.
  • VirtualMachineInstanceReplicaSet: Manages multiple replicas of a VirtualMachineInstance (for scaling).
  • VirtualMachineDisk: Defines the storage for a VM.

Step 3: Creating a Virtual Machine

There are two primary ways to create a VM:

  1. Using the virtctl command-line tool:

virtctl is a command-line utility specifically designed for interacting with Kubevirt.

  1. Create a YAML definition for your VM:

YAML



apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: my-vm
spec:
  running: false # VM will not start automatically
  template:
    metadata:
      labels:
        app: my-vm
    spec:
      domain:
        cpu:
          cores: 2
        memory:
          guest: 4Gi
      volumes:
      - name: rootdisk
        virtualMachineDisk:
          disk:
            bus: virtio
      - name: cloudinitdisk
        cloudInit:
          userData: |
            # Example cloud-init configuration
            # This will create a user 'myuser' with password 'password123'
            users:
              - name: myuser
                sudo: ALL=(ALL) NOPASSWD:ALL
                groups: sudo
                shell: /bin/bash
                sshAuthorizedKeys:
                  - ssh-rsa AAAAB3NzaC...  # Your SSH public key
      - name: cdrom
        cdrom: {}     
      networks:
      - name: pod-network
        pod: {}
  volumeMounts:
  - name: rootdisk
    mountPath: /
  - name: cloudinitdisk
    mountPath: /etc/cloud/cloud.cfg.d/01_config.cfg
  - name: cdrom
    mountPath: /mnt/cdrom

  1. Apply the YAML file:

Bash



oc apply -f my-vm.yaml

  1. Using the OpenShift Web Console:
  1. Navigate to the "Workloads" -> "Virtual Machines" section.
  2. Click "Create Virtual Machine."
  3. Fill in the required details, including the VM name, resources, operating system image, and storage. The web console provides a user-friendly interface for configuring these options.

Step 4: Starting and Stopping a Virtual Machine

Using virtctl:


Bash



virtctl start my-vm      # Start the VM
virtctl stop my-vm       # Stop the VM
virtctl restart my-vm    # Restart the VM

Using the Web Console: Use the buttons in the Virtual Machines list to start, stop, and restart VMs.

Step 5: Accessing the Virtual Machine

You can access the VM using virtctl's console command or by connecting via SSH (if you configured SSH access).


Bash



virtctl console my-vm   # Opens a console to the VM

For SSH, you'll need to determine the VM's IP address. You can do this through the OpenShift web console or by inspecting the VM's status using oc describe virtualmachine my-vm.

Step 6: Managing Virtual Machine Disks

VirtualMachineDisk CRDs define the storage for your VMs. You can create Persistent Volume Claims (PVCs) and reference them in your VirtualMachine definition. This allows you to leverage OpenShift's storage management capabilities.

Step 7: Networking

By default, VMs are connected to the pod network, which allows them to communicate with other pods in the cluster. You can configure different networking options, such as using a bridge network for direct access to the external network.

Step 8: Advanced Operations

  • Live Migration: Migrate running VMs between nodes without downtime.
  • Snapshots: Create snapshots of VMs for backup and recovery.
  • Cloning: Clone existing VMs to quickly create new ones.
  • Templates: Use VM templates to define reusable configurations.

Troubleshooting:

  • VM Not Starting: Check the VM's status and logs for any errors.
  • Connectivity Issues: Verify network configuration and firewall rules.
  • Resource Constraints: Ensure that the cluster has sufficient resources (CPU, memory, storage) to run the VM.

Key Considerations for Operators:

  • Resource Management: Plan for resource allocation for both containers and VMs.
  • Security: Implement appropriate security measures for VMs, including access control and isolation.
  • Monitoring: Monitor the performance and health of both VMs and containers.
  • Backup and Recovery: Develop a backup and recovery strategy for VMs.

This guide provides a basic introduction to OpenShift Virtualization. For more detailed information and advanced configurations, refer to the official Red Hat OpenShift documentation. By mastering OpenShift Virtualization, operators can effectively manage a hybrid environment of containers and VMs, streamlining operations and maximizing resource utilization.