Chapter 3. Deploying a RHEL image as a Google Compute Engine instance on GCP
To use a RHEL image on Google Cloud Platform (GCP), convert the image to a GCP-compatible format and deploy a VM from the image to run as an Google Compute Engine (GCE) VM. To create, customize, and deploy a RHEL image to GCE supported formats, you can use one of the following methods:
- Use the Red Hat image builder. For instructions, see Preparing and uploading custom GCE images to GCP.
- Manually create and configure a supported format image. This is a more complicated process but offers more granular customization options. For details, see the following sections.
For a list of Red Hat product certifications for GCP, see Red Hat on Google Cloud Platform.
Prerequisites
- You have created a Red Hat account.
- You have signed up and set up a GCP account.
3.1. Available RHEL image types for public cloud
To deploy your RHEL virtual machine VM on a certified cloud service provider (CCSP), you can use a number of options. The following table lists the available image types, subscriptions, considerations, and sample scenarios for the image types.
To deploy customized ISO images, you can use Red Hat Image Builder. With Image Builder, you can create, upload, and deploy these custom images specific to your chosen CCSP.
Image types | Subscriptions | Considerations | Sample scenario |
---|---|---|---|
Deploy a Red Hat Golden Image | Use your existing Red Hat subscriptions | The subscriptions include the Red Hat product cost and support for Cloud Access images, while you pay the CCSP for all other instance costs | Select a Red Hat Golden Image on the CCSP. For details on Golden Images and how to access them on the CCSP, see the Red Hat Cloud Access Reference Guide |
Deploy a custom image that you move to the CCSP | Use your existing Red Hat subscriptions | The subscriptions includes the Red Hat product cost and support for custom RHEL image, while you pay the CCSP for all other instance costs | Upload your custom image and attach your subscriptions |
Deploy an existing RHEL based custom machine image | The custom machine images include a RHEL image | You pay the CCSP on an hourly basis based on a pay-as-you-go model. For this model, on-demand images are available on the CCSP marketplace. The CCSP provides support for these images, while Red Hat handles updates. The CCSP provides updates through the Red Hat Update Infrastructure (RHUI) | Select a RHEL image when you launch an instance on the CCSP cloud management console, or choose an image from the CCSP marketplace. |
You cannot convert an on-demand instance to a custom RHEL instance. For migrating from an on-demand image to a custom RHEL bring your own subscription (BYOS) image:
- Create a new custom RHEL instance, then migrate data from your on-demand instance.
- When your data migration is completed, terminate the on-demand instance to avoid additional billing.
3.2. Deploying a RHEL instance by using a custom base image
To manually configure a virtual machine (VM), first create a base (starter) image. Then, you can modify configuration settings and add the packages the VM requires to operate on the cloud. You can also make additional configuration changes for your specific application after you upload the image.
Creating a VM from a base image has the following advantages:
- Fully customizable
- High flexibility for any use case
- Lightweight - includes only the operating system and the required runtime libraries
To create a custom base image of RHEL from an ISO image, you can use the command line interface (CLI) or the web console for creating and configuring VM.
Vertify the following VM configurations.
- ssh - ssh must be enabled to provide remote access to your VMs
- dhcp - the primary virtual adapter should be configured for dhcp.
Prerequisites
- You have enabled virtualization on the host machine.
For web console, ensure the following options:
- You have not checked the Immediately Start VM option.
- You have already changed the Memory size to your preferred settings.
- You have changed the Model option under Virtual Network Interface Settings to virtio and vCPUs to the capacity settings for the VM.
Procedure
Configure the Red Hat Enterprise Linux VM:
- To install from the command line (CLI), ensure that you set the default memory, network interfaces, and CPUs as per your requirement for the VM. For details, see Creating virtual machines by using the command line
- To install from the web console, see Creating virtual machines by using the web console
When the installation starts:
-
Create a
root
password. - Create an administrative user account.
-
Create a
-
After the installation completes, reboot the VM and log in to the
root
account. -
After logging in as
root
, you can configure the image. Register the VM and enable the RHEL repository:
subscription-manager register --auto-attach
# subscription-manager register --auto-attach
Copy to Clipboard Copied!
Verification
Verify that the
cloud-init
package is installed and enabled:dnf install cloud-init systemctl enable --now cloud-init.service
# dnf install cloud-init # systemctl enable --now cloud-init.service
Copy to Clipboard Copied! - Power down the VM.
3.3. Uploading and running a RHEL instance on GCP
To run your RHEL instance on Google Cloud Platform (GCP), you need to configure and upload a RHEL image to GCP.
3.3.1. Installing the Google Cloud SDK
You can use Google Cloud SDK to manage Google Cloud Platform (GCP) resources and services from your command line by using Google Cloud CLI.
Prerequisites
- You have downloaded, extracted, and initialized the Google Cloud SDK.
Procedure
-
Use the
gcloud
CLI utility to manage project and instances. Create a project:
gcloud projects create <example-gcp-project-id> --name <example-gcp-project>
# gcloud projects create <example-gcp-project-id> --name <example-gcp-project>
Copy to Clipboard Copied! The example creates a project with the project ID
<example-gcp-project-id>
and the project name<example-gcp-project>
.Display project information:
gcloud compute <example-project-info> describe --project <example-project-name>
# gcloud compute <example-project-info> describe --project <example-project-name>
Copy to Clipboard Copied!
3.3.2. Creating a new project on GCP
To upload your RHEL image to Google Cloud Platform (GCP), You need to create new project on GCP. A project manages your assigned Google Cloud resources.
Prerequisites
- You have an account on Google Cloud Platform.
Procedure
- Launch the GCP Console.
- Click the drop-down menu to the right of Google Cloud Platform.
- From the pop-up menu, click NEW PROJECT.
- From the New Project window, enter a name for your new project.
- Check Organization. Click the drop-down menu to change the organization, if necessary.
- Confirm the Location of your parent organization or folder. Click Browse to search for and change this value, if necessary.
- Click CREATE to create your new GCP project.
3.3.3. Creating and uploading a RHEL image on Google Cloud Storage
Create a GCP storage bucket to import and store objects such as VM images.
Procedure
Log in to the Google cloud console:
gcloud auth login
# gcloud auth login
Copy to Clipboard Copied! Create a storage bucket:
gsutil mb gs://<example-bucket-name>
# gsutil mb gs://<example-bucket-name>
Copy to Clipboard Copied! NoteAlternatively, you can use the Google Cloud Console to create a bucket. For details, see Create a bucket.
Specify the image name that you want to create, the existing bucket name, and the name of the image:
**gcloud compute images create my-image-name --source-uri gs://__<example-bucket-name>__/disk.raw.tar.gz**
# **gcloud compute images create my-image-name --source-uri gs://__<example-bucket-name>__/disk.raw.tar.gz**
Copy to Clipboard Copied! NoteAlternatively, you can use the Google Cloud Console to create an image. See Creating, deleting, and deprecating custom images for more information.
Optional: Find the image in the GCP Console.
- Click the Navigation menu to the left of the Google Cloud Console banner.
- Select Compute Engine and then Images.
Run the
qemu-img
command to convert yourqcow2
image to theraw
format:qemu-img convert -f qcow2 -O raw rhel-10.0-sample.qcow2 disk.raw
# qemu-img convert -f qcow2 -O raw rhel-10.0-sample.qcow2 disk.raw
Copy to Clipboard Copied! Compress the image:
tar --format=oldgnu -Sczf disk.raw.tar.gz disk.raw
# tar --format=oldgnu -Sczf disk.raw.tar.gz disk.raw
Copy to Clipboard Copied! Upload the image to the existing bucket:
gsutil cp disk.raw.tar.gz gs://<example-bucket-name>
# gsutil cp disk.raw.tar.gz gs://<example-bucket-name>
Copy to Clipboard Copied! NoteUpload could take a few minutes.
- From the Google Cloud Platform home screen, click the collapsed menu icon and select Storage and then select Browser.
Click the name of your bucket where
disk.raw.tar.gz
is now listed.NoteYou can also upload your image by using the GCP Console. To do so, click the bucket name and then click Upload files.
3.3.4. Launching and connecting to a RHEL Google Compute Engine instance
To configure a GCE VM instance from an image, use the GCP Console.
Procedure
- 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.
- Select your image.
- Click Create Instance.
- On the Create an instance page, enter a Name for your instance.
- Choose a Region and Zone.
- Choose a Machine configuration that meets or exceeds the requirements of your workload.
- Ensure that Boot disk specifies the name of your image.
- Optional: Under Firewall, select Allow HTTP traffic or Allow HTTPS traffic.
- Click Create.
- Find your image under VM instances.
Click the Navigation menu to the left of the Google Cloud Console banner and select Compute Engine and then select VM instances.
NoteAlternatively, you can use the
gcloud compute instances create
command to create a GCE VM instance from an image.gcloud compute instances create myinstance3 --zone=us-central1-a --image test-iso2-image
# gcloud compute instances create myinstance3 --zone=us-central1-a --image test-iso2-image
Copy to Clipboard Copied! The example creates a VM instance named
myinstance3
in zoneus-central1-a
based upon the existing imagetest-iso2-image
. For details, see gcloud compute instances create.Use the
ssh-keygen
utility to generate an SSH key pair to use with GCE by using the public IP address:ssh-keygen -t rsa -f ~/.ssh/google_compute_engine.pub
# ssh-keygen -t rsa -f ~/.ssh/google_compute_engine.pub
Copy to Clipboard Copied! - 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.
- Click SSH Keys and then click Edit.
-
Enter the output generated from the
~/.ssh/google_compute_engine.pub
file and click Save. Connect to the instance:
ssh -i ~/.ssh/google_compute_engine <username>@<instance_external_ip>
# ssh -i ~/.ssh/google_compute_engine <username>@<instance_external_ip>
Copy to Clipboard Copied! NoteAlternatively, you can run the
gcloud compute config-ssh
command to populate the config file with aliases for instances. The aliases allow simple SSH connections by instance name. For details, see gcloud compute config-ssh.
3.4. Attaching Red Hat subscriptions
Using the subscription-manager
command, you can register and attach your Red Hat subscription to a RHEL instance.
Prerequisites
- You have an active Red Hat account.
Procedure
Register your system:
subscription-manager register --auto-attach
# subscription-manager register --auto-attach
Copy to Clipboard Copied! Attach your subscriptions:
- You can use an activation key to attach subscriptions. See Creating Red Hat Customer Portal Activation Keys for more information.
- Alternatively, you can manually attach a subscription by using the ID of the subscription pool (Pool ID). See Attaching a host-based subscription to hypervisors.
Optional: To collect various system metrics about the instance in the Red Hat Hybrid Cloud Console, you can register the instance with Red Hat Insights.
insights-client register --display-name <display-name-value>
# insights-client register --display-name <display-name-value>
Copy to Clipboard Copied! For information on further configuration of Red Hat Insights, see Client Configuration Guide for Red Hat Insights.