Chapter 5. Deploying a Red Hat Enterprise Linux image as a Google Compute Engine instance on Google Cloud Platform

You have a number of options for deploying a Red Hat Enterprise Linux (RHEL) 8 image as a Google Compute Engine (GCE) instance on Google Cloud Platform (GCP). This chapter discusses your options for choosing an image and lists or refers to system requirements for your host system and VM. The chapter provides procedures for creating a custom image, uploading to GCE, and launching an instance.

This chapter refers to the Google documentation in a number of places. For many procedures, see the referenced Google documentation for additional detail.

Note

For a list of Red Hat product certifications for GCP, see Red Hat on Google Cloud Platform.

Prerequisites

  • You need a Red Hat Customer Portal account to complete the procedures in this chapter.
  • Create an account with GCP to access the Google Cloud Platform Console. See Google Cloud for more information.
  • Enable your Red Hat subscriptions through the Red Hat Cloud Access program. The Red Hat Cloud Access program allows you to move your Red Hat subscriptions from physical or on-premise systems onto GCP with full support from Red Hat.

5.1. Red Hat Enterprise Linux image options on GCP

The following table lists image choices and the differences in the image options.

Table 5.1. Image options

Image optionSubscriptionsSample scenarioConsiderations

Choose to deploy a custom image that you move to GCP.

Leverage your existing Red Hat subscriptions.

Enable subscriptions through the Red Hat Cloud Access program, upload your custom image, and attach your subscriptions.

The subscription includes the Red Hat product cost; you pay all other instance costs.

Custom images that you move to GCP are called "Cloud Access" images because you leverage your existing Red Hat subscriptions. Red Hat provides support directly for Cloud Access images.

Choose to deploy an existing GCP image that includes RHEL.

The GCP images include a Red Hat product.

Choose a RHEL image when you launch an instance on the GCP Compute Engine, or choose an image from the Google Cloud Platform Marketplace.

You pay GCP hourly on a pay-as-you-go model. Such images are called "on-demand" images. GCP offers support for on-demand images through a support agreement.

Note

You can create a custom image for GCP using Red Hat Image Builder. See Composing a Customized RHEL System Image for more information.

Important

You cannot convert an on-demand instance to a Red Hat Cloud Access instance. To change from an on-demand image to a Red Hat Cloud Access (BYOS) image, create a new Red Hat Cloud Access instance and migrate data from your on-demand instance. Cancel your on-demand instance after you migrate your data to avoid double billing.

The remainder of this chapter includes information and procedures pertaining to custom images.

5.2. Understanding base images

This section includes information on using preconfigured base images and their configuration settings.

5.2.1. Using a custom base image

To manually configure a VM, you start with a base (starter) VM image. Once you have created the base VM image, you can modify configuration settings and add the packages the VM requires to operate on the cloud. You can make additional configuration changes for your specific application after you upload the image.

The recommended base VM image is the Red Hat Enterprise Linux 8 KVM Guest Image, which you download from the Red Hat Customer Portal. The KVM Guest Image is preconfigured with the following cloud configuration settings.

  • The root account is disabled. You temporarily enable root account access to make configuration changes and install packages that the cloud may require. This guide provides instructions for enabling root account access.
  • A user account named cloud-user is preconfigured on the image. The cloud-user account has sudo access.
  • The image has cloud-init installed and enabled. cloud-init is a service that handles provisioning of the VM (or instance) at initial boot.

You can choose to use a custom Red Hat Enterprise Linux ISO image; however, when using a custom ISO image, you may need to make additional configuration changes.

Additional resources

Red Hat Enterprise Linux

5.2.2. Virtual machine configuration settings

Cloud VMs must have the following configuration settings.

Table 5.2. VM configuration settings

SettingRecommendation

ssh

ssh must be enabled to provide remote access to your VMs.

dhcp

The primary virtual adapter should be configured for dhcp.

5.3. Creating a base image from a KVM Guest Image

Follow the procedures in this section to create a base image from a KVM Guest Image.

Prerequisites

Enable virtualization for your Red Hat Enterprise Linux 8 host machine.

5.3.1. Downloading the KVM Guest Image

Procedure

  1. Download the latest Red Hat Enterprise Linux KVM Guest Image from the Red Hat Customer Portal.
  2. Move the image to /var/lib/libvirt/images.

5.3.2. Creating the VM from the KVM Guest Image

Procedure

  1. Ensure that you have enabled your host machine for virtualization. See Enabling virtualization in RHEL 8 for information and procedures.
  2. Create and start a basic Red Hat Enterprise Linux VM. See Creating virtual machines for instructions.

    1. If you use the command line to create your VM, ensure that you set the default memory and CPUs to the capacity you want for the VM. Set your virtual network interface to virtio.

      A basic command-line sample follows.

      virt-install --name kvmtest --memory 2048 --vcpus 2 --disk rhel-8.0-x86_64-kvm.qcow2,bus=virtio --import --os-variant=rhel8.0
    2. If you use the web console to create your VM, follow the procedure in Creating virtual machines using the web console, with these caveats:

      • Do not check Immediately Start VM.
      • Change your Memory size to your preferred settings.
      • Before you start the installation, ensure that you have changed Model under Virtual Network Interface Settings to virtio and change your vCPUs to the capacity settings you want for the VM.
  3. Shut down the new VM after a login prompt appears.

5.3.3. Setting up root access to your KVM Guest Image

You need root access to make additional configuration changes to your image. You can also use root as one method of accessing your image once you have uploaded the image to the cloud. Perform the following procedure to enable root access to your VM.

Procedure

  1. From your host system, use the virt-customize command to generate a root password for the VM.

    # virt-customize -a <guest-image-path> --root-password password:<PASSWORD>

    Example:

    # virt-customize -a /var/lib/libvirt/images/rhel-guest-image-8.0-120.x86_64.qcow2 --root-password password:redhat!
    [   0.0] Examining the guest ...
    [ 103.0] Setting a random seed
    [ 103.0] Setting passwords
    [ 112.0] Finishing off
  2. Use the virt-edit command to edit the cloud.cfg file on your VM. Within the file, enable root login and password authentication by setting disable_root to 0 and ssh_pwauth to 1.

    # virt-edit -a <guest-image-path> /etc/cloud/cloud.cfg
  3. Verify root access by starting the RHEL VM and logging in as root.
  4. Configure the image.
  5. Important: This step is only for VMs you intend to upload to AWS. Install the nvme, xen-netfront, and xen-blkfront drivers. which are required for RHEL 8.x images on AWS.

     # dracut -f --add-drivers "nvme xen-netfront xen-blkfront"

    Including these driver removes the possibility of a dracut time-out.

    Alternatively, you can add the drivers to /etc/dracut.conf.d/ and then enter dracut -f to overwrite the existing initramfs file.

  6. Power down the VM.

5.4. Creating a base VM from an ISO image

Follow the procedures in this section to create a base image from an ISO image.

Prerequisites

Enable virtualization for your Red Hat Enterprise Linux 8 host machine.

5.4.1. Downloading the ISO image

Procedure

  1. Download the latest Red Hat Enterprise Linux ISO image from the Red Hat Customer Portal.
  2. Move the image to /var/lib/libvirt/images.

5.4.2. Creating a VM from the ISO image

Procedure

  1. Ensure that you have enabled your host machine for virtualization. See Enabling virtualization in RHEL 8 for information and procedures.
  2. Create and start a basic Red Hat Enterprise Linux VM. See Creating virtual machines for instructions.

    1. If you use the command line to create your VM, ensure that you set the default memory and CPUs to the capacity you want for the VM. Set your virtual network interface to virtio.

      A basic command-line sample follows.

      virt-install --name isotest --memory 2048 --vcpus 2 --disk size=8,bus=virtio --location rhel-8.0-x86_64-dvd.iso --os-variant=rhel8.0
    2. If you use the web console to create your VM, follow the procedure in Creating virtual machines using the web console, with these caveats:

      • Do not check Immediately Start VM.
      • Change your Memory and Storage Size to your preferred settings.
      • Before you start the installation, ensure that you have changed Model under Virtual Network Interface Settings to virtio and change your vCPUs to the capacity settings you want for the VM.

5.4.3. Completing the RHEL installation

Perform the following steps to complete the installation and to enable root access once the VM launches.

Procedure

  1. Choose the language you want to use during the installation process.
  2. On the Installation Summary view:

    1. Click Software Selection and check Minimal Install.
    2. Click Done.
    3. Click Installation Destination and check Custom under Storage Configuration.

      • Verify at least 500 MB for /boot. You can use the remaining space for root /.
      • Standard partitions are recommended, but you can use Logical Volume Management (LVM).
      • You can use xfs, ext4, or ext3 for File System.
      • Click Done when you are finished with changes.
  3. Click Begin Installation.
  4. Set a Root Password. Create other users as applicable.
  5. Reboot the VM and log in as root once the installation completes.
  6. Configure the image.

    Note

    Ensure that the cloud-init package is installed and enabled.

  7. Important: This step is only for VMs you intend to upload to AWS. Install the nvme, xen-netfront, and xen-blkfront drivers. which are required for RHEL 8.x images on AWS.

     # dracut -f --add-drivers "nvme xen-netfront xen-blkfront"

    Including these driver removes the possibility of a dracut time-out.

    Alternatively, you can add the drivers to /etc/dracut.conf.d/ and then enter dracut -f to overwrite the existing initramfs file.

  8. Power down the VM.

5.5. Uploading the RHEL image to GCP

Follow the procedures in this section to upload your image to GCP.

5.5.1. Creating a new project on GCP

Complete the following steps to create a new project on GCP.

Prerequisites

You must have created an account with GCP. If you have not, see Google Cloud for more information.

Procedure

  1. Launch the GCP Console.
  2. Click the drop-down to the right of Google Cloud Platform.
  3. From the pop-up, click NEW PROJECT.
  4. From the New Project window, enter a name for your new project.
  5. Check the Organization. Click the drop-down menu to change the organization, if necessary.
  6. Confirm the Location of your parent organization or folder. Click Browse to search for and change this value, if necessary.
  7. Click CREATE to create your new GCP project.

    Note

    Once you have installed the Google Cloud SDK, you can use the gcloud projects create CLI command to create a project. A simple example follows.

    gcloud projects create my-gcp-project3 --name project3

    The example creates a project with the project ID my-gcp-project3 and the project name project3. See gcloud project create for more information.

Additional resources

Creating and Managing Resources

5.5.2. Installing the Google Cloud SDK

Complete the following steps to install the Google Cloud SDK.

Prerequisites

Procedure

  1. Follow the GCP instructions for downloading and extracting the Google Cloud SDK archive. See the GCP document Quickstart for Linux for details.
  2. Follow the same instructions for initializing the Google Cloud SDK.

    Note

    Once you have initialized the Google Cloud SDK, you can use the gcloud CLI commands to perform tasks and obtain information about your project and instances. For example, you can display project information with the gcloud compute project-info describe --project <project-name> command.

5.5.3. Creating SSH keys for Google Compute Engine

Perform the following procedure to generate and register SSH keys with GCE so that you can SSH directly into an instance using its public IP address.

Procedure

  1. Use the ssh-keygen command to generate an SSH key pair for use with GCE.

    # ssh-keygen -t rsa -f ~/.ssh/google_compute_engine
  2. From the GCP Console Dashboard page, click the Navigation menu to the left of the Google Cloud Console banner and select Compute Engine and then select Metadata.
  3. Click SSH Keys and then click Edit.
  4. Enter the output generated from the ~/.ssh/google_compute_engine.pub file and click Save.

    Note

    If the Red Hat image you configured was a KVM Guest Image, the user name for your key must be cloud-user, which is the default user.

    You can now connect to your instance using standard SSH.

    # ssh -i ~/.ssh/google_compute_engine <username>@<instance_external_ip>
Note

You can run the gcloud compute config-ssh command to populate your config file with aliases for your instances. The aliases allow simple SSH connections by instance name. For information on the gcloud compute config-ssh command, see gcloud compute config-ssh.

5.5.4. Creating a storage bucket in GCP Storage

Importing to GCP requires a GCP Storage Bucket. Complete the following steps to create a bucket.

Procedure

  1. If you are not already logged in to GCP, log in with the following command.

    # gcloud auth login
  2. Create a storage bucket.

    # gsutil mb gs://bucket_name
    Note

    Alternatively, you can use the Google Cloud Console to create a bucket. See Create a bucket for information.

Additional resources

Create a bucket

5.5.5. Converting and uploading your image to your GCP Bucket

Complete the following procedure to convert and upload your image to your GCP Bucket. The samples are representative; they convert a qcow2 image to raw format and then tar that image for upload.

Procedure

  1. Run the qemu-img command to convert your image. The converted image must have the name disk.raw.

    # qemu-img convert -f qcow2 -O raw gc-iso-dvd.qcow2 disk.raw
  2. Tar the image.

    # tar --format=oldgnu -Sczf disk.raw.tar.gz disk.raw
  3. Upload the image to the bucket you created previously. Upload could take a few minutes.

    # gsutil cp disk.raw.tar.gz gs://bucket_name
  4. From the Google Cloud Platform home screen, click the collapsed menu icon and select Storage and then select Browser.
  5. Click the name of your bucket.

    The tarred image is listed under your bucket name.

    Note

    You can also upload your image using the GCP Console. To do so, click the name of your bucket and then click Upload files.

5.5.6. Creating an image from the object in the GCP bucket

Perform the following procedure to create an image from the object in your GCP bucket.

Procedure

  1. Run the following command to create an image for GCE. Specify the name of the image you are creating, the bucket name, and the name of the tarred image.

    # gcloud compute images create my-image-name --source-uri gs://my-bucket-name/disk.raw.tar.gz
    Note

    Alternatively, you can use the Google Cloud Console to create an image. See Creating, deleting, and deprecating custom images for information.

  2. Optionally, find the image in the GCP Console.

    1. Click the Navigation menu to the left of the Google Cloud Console banner.
    2. Select Compute Engine and then Images.

5.5.7. Creating a Google Compute Engine instance from an image

Complete the following steps to configure a GCE VM instance using the GCP Console.

Note

The following procedure provides instructions for creating a basic VM instance using the GCP Console. See Creating and starting a VM instance for more information on GCE VM instances and their configuration options.

Procedure

  1. From the GCP Console Dashboard page, click the Navigation menu to the left of the Google Cloud Console banner and select Compute Engine and then select Images.
  2. Select your image.
  3. Click Create Instance.
  4. On the Create an instance page, enter a Name for your instance.
  5. Choose a Region and Zone.
  6. Choose a Machine configuration that meets or exceeds the requirements of your workload.
  7. Ensure that Boot disk specifies the name of your image.
  8. Optionally, under Firewall, select Allow HTTP traffic or Allow HTTPS traffic.
  9. Click Create.

    Note

    These are the minimum configuration options necessary to create a basic instance. Review additional options based on your application requirements.

  10. Find your image under VM instances.
  11. From the GCP Console Dashboard, click the Navigation menu to the left of the Google Cloud Console banner and select Compute Engine and then select VM instances.

    Note

    Alternatively, you can use the gcloud compute instances create CLI command to create a GCE VM instance from an image. A simple example follows.

    gcloud compute instances create myinstance3 --zone=us-central1-a --image test-iso2-image

    The example creates a VM instance named myinstance3 in zone us-central1-a based upon the existing image test-iso2-image. See gcloud compute instances create for more information.

5.5.8. Connecting to your instance

Perform the following procedure to connect to your GCE instance using its public IP address.

Procedure

  1. Run the following command to ensure that your instance is running. The command lists information about your GCE instance, including whether the instance is running, and, if so, the public IP address of the running instance.

    # gcloud compute instances list
  2. Connect to your instance using standard SSH. The example uses the google_compute_engine key created earlier.

    Note

    If the Red Hat image you configured was a KVM Guest Image, use cloud-user, which is the default user name.

    # ssh -i ~/.ssh/google_compute_engine <user_name>@<instance_external_ip>
    Note

    GCP offers a number of ways to SSH into your instance. See Connecting to instances for more information. You can also connect to your instance using the root account and password you set previously.

5.5.9. Attaching Red Hat subscriptions

Complete the following steps to attach the subscriptions you previously enabled through the Red Hat Cloud Access program.

Prerequisites

You must have enabled your subscriptions.

Procedure

  1. Register your system.

    subscription-manager register --auto-attach
  2. Attach your subscriptions.